db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alan Burlison <Alan.Burli...@sun.com>
Subject Re: Returning NULL from a database-side Java function
Date Wed, 10 Oct 2007 08:19:01 GMT
Knut Anders Hatlen wrote:

>>> 1. Why does int pop = 0 == 0 ? 1 : null; even compile?
>> Maybe the compiler figures out that it's the same as pop = 1 so it 
>> discards the null? Seems like it shouldn't compile.
> 
> Or could it be auto-boxing that makes it compilable? This equivalent
> code (which is what auto-boxing would rewrite it to, I think) should
> compile:
> 
> int pop = 0 == 0 : 1 : ((Number) null).intValue();

Close, very close ;-)  Here's what happens:

int i = 0 == 0 ? null : 1;

    0:   aconst_null
    1:   checkcast       #2; //class java/lang/Integer
    4:   invokevirtual   #3; //Method java/lang/Integer.intValue:()I
    7:   istore_1
    8:   return

So it is autoboxing to Integer, then calling intValue().  This sure 
looks like a Java bug to me, I've asked internally to see if anyone can 
confirm, and if so I'll raise a bug against javac.

-- 
Alan Burlison
--

Mime
View raw message