-1

When I have a method like:

public class Tttttt {

    public Thing getThingBy(String name) {
      return aaa.getThingBy(name);
    }
}

And then I see in logs NPE

Caused by java.lang.NullPointerException
   at xxx.yyy.Tttttt.getThingBy(SourceFile:666)

And the 666 fits the method definition, then can I say whether name was null or aaa was null?

Marian Paździoch
  • 8,813
  • 10
  • 58
  • 103

2 Answers2

2

In this case aaa is null.

name also can be null but it will be passed to the getThingBy as a parameter and you'd have more entries in your stack trace if the exception was thrown down there.

Ivan
  • 3,781
  • 16
  • 20
1

can I say whether name was null or aaa was null?

This is a poor example... aaa is most certainly null. Passing a null parameter into that method doesn't throw any exception. Even if the method did call itself, you'd see that in the stacktrace.

Say it did get called again, and you used aaa.someMethod(name.length()) on the exact same line. Then you might still be able to determine the variable based on the class type and method mentioned in the stacktrace, as for this question at xxx.yyy.Tttttt.getThingBy compared to Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245