• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [OT] Weird Boolean/ Wrapper class bug
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [OT] Weird Boolean/ Wrapper class bug


  • Subject: Re: [OT] Weird Boolean/ Wrapper class bug
  • From: "Shravan Kumar. M" <email@hidden>
  • Date: Sat, 21 Nov 2009 18:44:50 -0800 (PST)

Thanks for your example and analysis Mike. When I run your example from a simple file over command-line everything is fine and when I put this code this Application.java, even then its fine...

But the error happens from a EO class and when I debug and test this code snippet in Display view, same error is shown there... so, the problem is getting more interesting and fuzzy. One thing I can surely say, error is inconsistent and is reproducible.

My java full version: java full version "1.5.0_16-b06-284"

Thank You,
Shravan Kumar. M
---------------------------------

Re: [OT] Weird Boolean/ Wrapper class bug

November 22, 2009 7:39:08 AM GMT+05:30
From:
"Mike Schrag" <email@hidden>
To:
"WO Dev Group" <email@hidden>
Incidentally, boxing/unboxing actually happens at compile time ... Once you run that code and verify if it works or not, then do the same inside of Eclipse and see if it fails (assuming you are compiling this from eclipse not javac). If that fails, run

javap -c Test

and you can see the decompiled code ... There should be no boxing/unboxing calls (basically, you shouldn't see an invokevirtual except for the println), you should just see an ifnull.

ms

On Nov 21, 2009, at 9:02 PM, Mike Schrag wrote:

I just tested that code under JDK 1.5.0_16-b06-275 on Tiger and it works for me. Incidentally, my rule of thumb is "if you think it's a VM, you're wrong. it's your fault." This rule of thumb has never failed me.

In a sample java file:

public class Test {
        public static void main(String[] args) {
                Boolean a = null;
                if(a != null)
                        System.out.println("s");
                else
                        System.out.println("n");
        }
}

emerald:~ local$ java -fullversion
java full version "1.5.0_16-b06-275"
emerald:~ local$ javac Test.java 
emerald:~ local$ java Test
n

javac that and run it and see if that fails for you.

ms

On Nov 21, 2009, at 7:55 PM, Shravan Kumar. M wrote:

Hello Mike,

Its the same code I have showed you (except that I changed variable names for simplicity), and there is no line of code that is missing. Where "a" is the EO property and when I check for it (  if(a != null) JRE throws NPE and when I check for if(a == null), JRE enjoys ), its throwing exception as stated. I believe this is a bug with JRE, and it seems to be fixed as per David's testing in later versions of JRE.

I think fix would be JRE shouldn't have unboxed it if its null... and they seems to have realized this mistake in later versions of JRE... But its wondering how a null & not null check differs in this world and they are not same from JRE perspective!!! If its an error it should have thrown error always...

Thank You,
Shravan Kumar. M


From: Mike Schrag <email@hidden>
To: Shravan Kumar. M <email@hidden>
Cc: WO Dev Group <email@hidden>
Sent: Sat, November 21, 2009 9:26:57 PM
Subject: Re: [OT] Weird Boolean/ Wrapper class bug

You're not pasting the real code, I don't think. I suspect you're just getting screwed by autoboxing in whatever code you're not showing. If you have:

Boolean a = null;
boolean b = a;

That will result in a NPE as auto-unboxing attempts to unbox a into a boolean, which throws a NPE. Somewhere in the code you didn't include is an unbox into a boolean (little b) of your null Boolean.

So, for instance:

Boolean a = null;
if (a) {
}

will NPE. Look more closely at the exact code, specifically the line of code that actually failing, and make sure you're not getting an unbox.

ms

On Nov 21, 2009, at 10:23 AM, Shravan Kumar. M wrote:

Hello Group,

Boolean a = null;
if(a != null)
System.out.println("s");
else 
System.out.println("n");
----------
Above code block raises NullPointerException, where as below one runs successfully!!! Same is the case with any wrapper class (Integer, Long, ...).
*Its wondering what it makes difference in checking (a != null)  and (a == null)? Its just an Object check rt!*

Exact exception: java.lang.NullPointerException at booleanValue()
----------
Boolean a = null;
if(a == null)
System.out.println("s");
else 
System.out.println("n");

Thank You,

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: [OT] Weird Boolean/ Wrapper class bug
      • From: Q <email@hidden>
  • Prev by Date: Re: [OT] Weird Boolean/ Wrapper class bug
  • Next by Date: Re: [OT] Weird Boolean/ Wrapper class bug
  • Previous by thread: Re: [OT] Weird Boolean/ Wrapper class bug
  • Next by thread: Re: [OT] Weird Boolean/ Wrapper class bug
  • Index(es):
    • Date
    • Thread