db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Knut Anders Hatlen <Knut.Hat...@Sun.COM>
Subject Re: Returning NULL from a database-side Java function
Date Tue, 09 Oct 2007 16:46:09 GMT
ty den 09.10.2007 klokka 09:01 (-0700) skreiv Daniel John Debrunner:
> Alan Burlison wrote:
> > Rick Hillegas wrote:
> > 
> >> It is hard to say where the NullPointerException originates. Could you 
> >> post a reproducible test case and the full stack trace from derby.log? 
> > 
> > Umm, it may be my bad, I have the following:
> > 
> >     public static int iGoBang() {
> >         int pop = 0 == 0 ? 1 : null;
> >         return pop;
> >     }
> > 
> > Which compiles but blows up, whereas
> > 
> >     public static int iGoBang() {
> >         return null;
> >     }
> > 
> > won't even compile.  Because you can't assign null to a primitive type - 
> > duh.  Which leaves 2 questions:
> > 
> > 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();

-- 
Knut Anders


Mime
View raw message