POV-Ray : Newsgroups : povray.off-topic : Any Java experts? Server Time
11 Oct 2024 01:22:42 EDT (-0400)
  Any Java experts? (Message 1 to 8 of 8)  
From: Gail Shaw
Subject: Any Java experts?
Date: 17 Jan 2008 14:05:25
Message: <478fa6f5@news.povray.org>
Is there anyone who can tell me why the following code sometimes (not
always) throws a NullPointerException
Using Java(TM) SE Runtime Environment (build 1.6.0_02-b06)

Node currentNode = Universe.space[i][j]; // Have checked and this is never
null.
if (currentNode.hasShip()) { // <-- This line sometimes throws a
NullPointerException
g.drawChars(Labels, 0, 1, i*GridSizeX+GridSizeX/2, j*GridSizeY);
}
if (currentNode.hasAsteroid() ) {
g.drawChars(Labels, 1, 1, i*GridSizeX+1, j*GridSizeY);
}


And here's an abbreviated version of the Node class. The local variable
localShip is never instantiated.
public class Node {


private Ship localShip;
private Asteroid localAsteroid;

boolean hasAsteroid() {
if (localAsteroid!=null)
return true;
else
return false;
}


boolean hasShip() {
if (localShip!=null)
return true;
else
return false;
}

}


Post a reply to this message

From: Orchid XP v7
Subject: Re: Any Java experts?
Date: 17 Jan 2008 16:15:21
Message: <478fc569$1@news.povray.org>
Gail Shaw wrote:

> boolean hasShip() {
> if (localShip!=null)
> return true;
> else
> return false;
> }

This cannot possibly throw a null pointer exception.

 > Node currentNode = Universe.space[i][j]; // Have checked and this is 
never
 > null.
 > if (currentNode.hasShip()) { // <-- This line sometimes throws a
 > NullPointerException

The only way for a null pointer exception to occur is if currentNode is 
null.

Looks like whatever initialises Universe.space isn't doing it right, or 
has some kind of intermittent bug or something. (Alternatively, the 
exception isn't comming from where you say it is.)

Realistically, you'll probably need to run the code through a debugger 
and make it halt execution when it hits the exception, then poke around 
and examine the system state...

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

From: Darren New
Subject: Re: Any Java experts?
Date: 17 Jan 2008 22:25:17
Message: <47901c1d$1@news.povray.org>
Gail Shaw wrote:
> Is there anyone who can tell me why the following code sometimes (not
> always) throws a NullPointerException
> Using Java(TM) SE Runtime Environment (build 1.6.0_02-b06)
> 
> Node currentNode = Universe.space[i][j]; // Have checked and this is never
> null.

Then you should have an assertion in there to that effect. :-)

> And here's an abbreviated version of the Node class.

Your exception isn't being caused at this line. Or your JVM is broken. 
Or currentNode is winding up a subclass of Node with different code.


Print everything just before you get there, or wrap the whole 
questionable chunk in a try/catch and print out everything when it throws.

-- 
   Darren New / San Diego, CA, USA (PST)
     It's not feature creep if you put it
     at the end and adjust the release date.


Post a reply to this message

From: Orchid XP v7
Subject: Re: Any Java experts?
Date: 18 Jan 2008 04:44:51
Message: <47907513$1@news.povray.org>
Darren New wrote:

>> Node currentNode = Universe.space[i][j]; // Have checked and this is 
>> never
>> null.
> 
> Then you should have an assertion in there to that effect. :-)

...Java has assertions now? Wow, neat. Are they broken?

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

From: Gail Shaw
Subject: Re: Any Java experts?
Date: 18 Jan 2008 11:37:14
Message: <4790d5ba@news.povray.org>
"Orchid XP v7" <voi### [at] devnull> wrote in message
news:478fc569$1@news.povray.org...
> Gail Shaw wrote:
>
> > boolean hasShip() {
> > if (localShip!=null)
> > return true;
> > else
> > return false;
> > }
>
> This cannot possibly throw a null pointer exception.

Yeah, that's what I thought. Eclipse keeps giving me a null pointer excption
and pointing at that line.
Really odd thing is that the exception isn't halting execution.

>  > Node currentNode = Universe.space[i][j]; // Have checked and this is
> never
>  > null.
>  > if (currentNode.hasShip()) { // <-- This line sometimes throws a
>  > NullPointerException
>
> The only way for a null pointer exception to occur is if currentNode is
> null.

Which it's not. I have print statements checking that. Removed them from the
post for clarity


Post a reply to this message

From: Gail Shaw
Subject: Re: Any Java experts?
Date: 18 Jan 2008 11:41:55
Message: <4790d6d3@news.povray.org>
"Darren New" <dne### [at] sanrrcom> wrote in message
news:47901c1d$1@news.povray.org...
> Gail Shaw wrote:
> > Is there anyone who can tell me why the following code sometimes (not
> > always) throws a NullPointerException
> > Using Java(TM) SE Runtime Environment (build 1.6.0_02-b06)
> >
> > Node currentNode = Universe.space[i][j]; // Have checked and this is
never
> > null.
>
> Then you should have an assertion in there to that effect. :-)

Could, but the way the initialisation of the Universe works, if any Node was
null, things would break a lot earlier than this.
I have print statements. Removed from post for clarity.

> > And here's an abbreviated version of the Node class.
>
> Your exception isn't being caused at this line. Or your JVM is broken.

Both are possibilities I've considered.

> Or currentNode is winding up a subclass of Node with different code.

Nothing inherits from Node.

> Print everything just before you get there, or wrap the whole
> questionable chunk in a try/catch and print out everything when it throws.

I'll do that. Probably find the excption's migrated elsewhere.

What I find really odd is that the exception doesn't terminate execution,
which I thought it should (would in C#)
Unless the exception's coming from elsewhere (the IDE possibly, or some
graphical component)


Post a reply to this message

From: Darren New
Subject: Re: Any Java experts?
Date: 18 Jan 2008 18:39:57
Message: <479138cd@news.povray.org>
Gail Shaw wrote:
> Yeah, that's what I thought. Eclipse keeps giving me a null pointer excption
> and pointing at that line.

Try running it not under eclipse, then?

> Really odd thing is that the exception isn't halting execution.

Maybe it's throwing in a thread, and eclipse can't figure that out?

-- 
   Darren New / San Diego, CA, USA (PST)
     It's not feature creep if you put it
     at the end and adjust the release date.


Post a reply to this message

From: Darren New
Subject: Re: Any Java experts?
Date: 18 Jan 2008 18:40:15
Message: <479138df$1@news.povray.org>
Orchid XP v7 wrote:
> Darren New wrote:
> 
>>> Node currentNode = Universe.space[i][j]; // Have checked and this is 
>>> never
>>> null.
>>
>> Then you should have an assertion in there to that effect. :-)
> 
> ....Java has assertions now? Wow, neat. Are they broken?

Every language has assertions. Some just have it built in.

-- 
   Darren New / San Diego, CA, USA (PST)
     It's not feature creep if you put it
     at the end and adjust the release date.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.