No StackTrace in java.lang.NullPointerException

Discussion in 'Java' started by Mr Smith, Feb 21, 2005.

  1. Mr Smith

    Mr Smith Guest

    Hello,

    in my app, i catch a java.lang.NullPointerException but the stackTrace is empty:

    "ex"= NullPointerException (id=44)
    cause= NullPointerException (id=44)
    detailMessage= null
    stackTrace= null

    It's hard to debug whith this. Is there any option to pass to the JVM to force setting the stack trace? Or Does it come from a bad throw ? (i haven't wrote all the source code i'm working on), or from a bad catch?

    Thx for your help
     
    Mr Smith, Feb 21, 2005
    #1
    1. Advertisements

  2. Mr Smith

    Mr Smith Guest

    some Infos:
    java.runtime.name = Java(TM) 2 Runtime Environment, Standard Edition
    java.vm.version = 1.4.2_06-b03
    java.vm.vendor = Sun Microsystems Inc.
    java.vm.name = Java HotSpot(TM) Client VM
    java.runtime.version = 1.4.2_06-b03
    java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
    os.arch = i386
    os.name = Linux
    java.class.version = 48.0
    os.version = 2.6.3-7mdk-i686-up-4GB
    file.encoding = ISO-8859-15
    java.specification.version = 1.4
    java.vm.specification.version = 1.0
    sun.arch.data.model = 32
    java.vm.info = mixed mode
    java.version = 1.4.2_06
    sun.cpu.endian = little


    Thx for your help
     
    Mr Smith, Feb 21, 2005
    #2
    1. Advertisements


  3. On the assumption that you are using some library
    that the owner is trying to keep you from peeking into
    I tried this:

    class Secret {
    private static void m1() {
    m2();
    }
    private static void m2() {
    NullPointerException ex = new NullPointerException();
    ex.setStackTrace(new StackTraceElement[0]);
    throw ex;
    }
    public static void main(String[] arg) {
    try {
    m1();
    } catch (NullPointerException ex) {
    System.out.println(ex.getCause());
    System.out.println(ex.getMessage());
    System.out.println(ex.getStackTrace());
    }
    }
    }

    But the stack trace is an empty StackTraceElement vector (not null).

    I guess someone could be doing this with JNI?


    One option is to wrap any external classes / methods and throw a new
    exception (there are exceptions that will allow you to wrap the original
    exception) so at least you know where you are in your code when the
    exception occurs.


    All this assuming you have not found a bug in the VM (unlikely).
     
    Thomas Schodt, Feb 21, 2005
    #3
  4. Mr Smith

    Mr Smith Guest


    Some it was a bug in the JVM:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5098422

    I've downloaded the last version of 1.4.2:

    java.runtime.name = Java(TM) 2 Runtime Environment, Standard Edition
    java.vm.version = 1.4.2_07-b05
    java.vm.vendor = Sun Microsystems Inc.
    java.vm.name = Java HotSpot(TM) Client VM
    java.vm.specification.name = Java Virtual Machine Specification
    java.runtime.version = 1.4.2_07-b05
    java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
    os.arch = i386
    os.name = Linux
    java.class.version = 48.0
    os.version = 2.6.3-7mdk-i686-up-4GB
    file.encoding = ISO-8859-15
    java.specification.version = 1.4
    java.vm.specification.version = 1.0
    sun.arch.data.model = 32
    java.specification.vendor = Sun Microsystems Inc.
    java.vm.info = mixed mode
    java.version = 1.4.2_07
    java.vendor = Sun Microsystems Inc.

    i've set the cmd line argument:

    -XX:-OmitStackTraceInFastThrow


    but it still doesn't work...

    I think i'm gonna report a bug.
     
    Mr Smith, Feb 21, 2005
    #4
  5. Mr Smith

    Mr Smith Guest

    well...
     
    Mr Smith, Feb 21, 2005
    #5
  6. Mr Smith

    Roland Guest

    AFAIK there no option to force the JVM to generate a stacktrace.
    Normally an exception does contain a stacktrace. However if your code
    (or the code you're using) uses JNI, then some native library could have
    triggered the NPE without properly filling a stacktrace or even a detail
    message. (I doubt the native libraries of the Java JRE are doing this).

    Another cause might be an OutOfMemoryError, preventing the JVM to
    generatate a proper stack trace. The times that I was able to catch an
    OutOfMemoryError, it never contained a stacktrace.
    --
    Regards,

    Roland de Ruiter
    ___ ___
    /__/ w_/ /__/
    / \ /_/ / \
     
    Roland, Feb 21, 2005
    #6
  7. If you are using Eclipse, you can go to Run->Add Java Exception
    Breakpoint and set a breakpoint for NullPointerException. Then you can
    stop the execution when the exception is thrown.
    If you are not using Eclipse, then you should use it :)
    I'm curious to see if this is a JVM bug.
     
    Andrea Desole, Feb 21, 2005
    #7
  8. Mr Smith

    Mr Smith Guest

    It's solved, but i don't know where it came from.

    No we print the stack trace somewhere else, in a different way (no toString()) and it works. I can't explain why.

    The good thing is that no i understand how the JV M handle stack traces of exceptions:
    - throw => save the stacktrace in the JVM (can't be reach)
    - print => build an array in java memory from the JVM memory and print it

    Thx for your help
     
    Mr Smith, Feb 21, 2005
    #8
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.