Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question about null pointers



----- Original Message ----- 
From: "Nicholas R. Rinard" <email@hidden>
To: "Java Listserv java-dev" <email@hidden>
Sent: Thursday, April 14, 2005 8:27 PM
Subject: Re: question about null pointers


> Alas, we may never know,

  if (model.equals(null)) System.out.println("null");

    6: putfield #2; //Field model:Ljava/lang/Object;
   9: aload_0
   10: getfield #2; //Field model:Ljava/lang/Object;
   13: aconst_null
   14: invokevirtual #3; //Method
java/lang/Object.equals:(Ljava/lang/Object;)Z
   17: ifeq 28
   20: getstatic #4; //Field java/lang/System.out:Ljava/io/PrintStream;

Invokes a method java/lang/Object.equals:(Ljava/lang/Object;)Z
which can NullPointerException if the first java/lang/Object is null.

if (model == null) System.out.println("null");

  5: aconst_null
   6: putfield #2; //Field model:Ljava/lang/Object;
   9: aload_0
   10: getfield #2; //Field model:Ljava/lang/Object;
   13: ifnonnull 24
   16: getstatic #3; //Field java/lang/System.out:Ljava/io/PrintStream;

Does not invoke a method to NPE.
Impossible as stated or the compiler is broke or doing something very
different or the JVM is broke or doing something very different, either way
it would not be different in a good way.
javap -c
output fwiw.

Mike Hall      mikehall at spacestar dot net
http://www.spacestar.net/users/mikehall


 _______________________________________________
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

References: 
 >Re: question about null pointers (From: Greg Guerin <email@hidden>)
 >Re: question about null pointers (From: "Nicholas R. Rinard" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.