Alas, we may never know, because I decided to just change the code
(ahem, improve the code) instead of figuring it out. Dmitry Markmak
suggested that it might be a compiler optimization error. That's my
favorite theory since all the other possible theories would be, you
know, my fault.
I was compiling using Xcode with Optimization level "-O3 Optimization
for speed; larger size". GCC v3.3, Java 1.4, on the current version of
the OS.
Here are some details, though I reiterate that this is no longer a
problem for me. The code in question was all in my large application
controller class (MVC type controller). "model" was a protected final
variable belonging to the controller class, initialized in the
constructor. later in the constructor, my code called, in a roundabout
way, a method in an inner class of the controller class. in that
method, it was clear that accessing "model" was the culprit, as i
could break up the code, add whitespace, add printouts, and no matter
what the first time i tried to frob "model" i would get a NPE
registered to the first time i touched "model". and, strangely, that
included the line to check whether model was null.
On Apr 14, 2005, at 6:01 PM, Greg Guerin wrote:
"Nicholas R. Rinard" <email@hidden> wrote:
if( model == null ) {
and, shockingly, this line of code is throwing a null pointer
exception. this line of code is called from within my app startup
routine but is called after model is initialized.
A NullPointerException in that expression should be impossible. The
bytecodes that should be compiled for that statement are specifically
designed to work with null and not throw NPE.
Please provide an example that consistently throws the exception.
Also,
which Java version and OS version is this happening on?
One possible explanation is that the line-number stated in the
exception is
only approximate, and the real culprit is on a nearby line, either
before
or after the line-number in the exception.
Another possibility is that the source wasn't recompiled, so the
line-number in the class-file is exact but you're looking at source
that
doesn't match the executed bytecodes.
Those are just guesses, though.
If you're absolutely certain it's not a mistake like the above, you
can use
the 'javap -c' command to disassemble the class's bytecodes (read 'man
javap' for info). You should see an 'ifnonnull' bytecode where your
source
has 'if (model==null)'. An ifnonnull branches when its operand is
non-null, therefore it would execute the following code, the body of
your
'if', when its operand (model) is null.
-- GG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden
This email sent to email@hidden