Why is this assertion being triggered?

T

thebad1

Hi,

I have a strange error, that I can reproduce using jre1.5.0_09 or
jdk1.5.0_10 on winXP using eclipse debugger, in Netbeans 5.0 and using
javac/java command line.

I have this line in my code;
assert !Double.isNaN(tRating) : "!Double.isNaN(tRating), tRating="+
tRating;

and it is triggering the following AssertionError.

Exception in thread "main" java.lang.AssertionError:
!Double.isNaN(tRating), tRating=3.6119877801230094
at packages.Netflix.predictRating(Netflix.java:250)
at packages.Netflix.train(Netflix.java:170)
at packages.Netflix.main(Netflix.java:122)

At the point the Error is triggered in eclipse, I can inspect the
values, and it is clear that the value is a valid double. However if I
drop to frame and rerun the code, the pointer passes the assertion with
no problem a second time. Also if I rerun the code again, the assertion
is triggered but with a different value of tRating.
 
P

Patricia Shanahan

thebad1 said:
Hi,

I have a strange error, that I can reproduce using jre1.5.0_09 or
jdk1.5.0_10 on winXP using eclipse debugger, in Netbeans 5.0 and using
javac/java command line.

I have this line in my code;
assert !Double.isNaN(tRating) : "!Double.isNaN(tRating), tRating="+
tRating;

and it is triggering the following AssertionError.

Exception in thread "main" java.lang.AssertionError:
!Double.isNaN(tRating), tRating=3.6119877801230094
at packages.Netflix.predictRating(Netflix.java:250)
at packages.Netflix.train(Netflix.java:170)
at packages.Netflix.main(Netflix.java:122)

At the point the Error is triggered in eclipse, I can inspect the
values, and it is clear that the value is a valid double. However if I
drop to frame and rerun the code, the pointer passes the assertion with
no problem a second time. Also if I rerun the code again, the assertion
is triggered but with a different value of tRating.

Given those symptoms, I would look VERY closely at whatever is supposed
to synchronize accesses and updates to tRating.

It is behaving exactly like a variable that is being updated from at
least one other thread while the assertion executes, so that it is a NaN
when the test is done, but something else when it is converted to String
for concatenation.

Patricia
 
D

Daniel Pitts

Patricia said:
Given those symptoms, I would look VERY closely at whatever is supposed
to synchronize accesses and updates to tRating.

It is behaving exactly like a variable that is being updated from at
least one other thread while the assertion executes, so that it is a NaN
when the test is done, but something else when it is converted to String
for concatenation.

Patricia

I would also put the value of "!Double.isNaN(tRating)" in the output of
the assertion, make sure that THAT is evaluating the way you expect:

assert !Double.isNaN(tRating) : "!Double.isNaN(tRating)=" +
!Double.isNaN(tRating), tRating="+ tRating;

Just in case.
 
T

thebad1

Patricia said:
Given those symptoms, I would look VERY closely at whatever is supposed
to synchronize accesses and updates to tRating.

It is behaving exactly like a variable that is being updated from at
least one other thread while the assertion executes, so that it is a NaN
when the test is done, but something else when it is converted to String
for concatenation.

This is what's really causing my brain to hurt, as it's just a simple
loop in a main method, there's no fun and games or threads or suchlike.

I'm not sure how significant this is; but the exact same class running
with the same params, "-Xmx758m -ea" and the same datafiles, on a
RHELinux ES 3 box with jdk-1.6.0-fcs does not hit these assertions.

Tom
 
P

Patricia Shanahan

thebad1 said:
This is what's really causing my brain to hurt, as it's just a simple
loop in a main method, there's no fun and games or threads or suchlike.

I'm not sure how significant this is; but the exact same class running
with the same params, "-Xmx758m -ea" and the same datafiles, on a
RHELinux ES 3 box with jdk-1.6.0-fcs does not hit these assertions.

Again, different behavior on different systems is very typical of
unsynchronized multi-threaded access.

Are you sure there isn't even a tiny little invokeLater :)

How about a short, simple, self-contained example?

Patricia
 
M

Mark Space

thebad1 said:
Hi,

I have a strange error, that I can reproduce using jre1.5.0_09 or
jdk1.5.0_10 on winXP using eclipse debugger, in Netbeans 5.0 and using
javac/java command line.

I have this line in my code;
assert !Double.isNaN(tRating) : "!Double.isNaN(tRating), tRating="+
tRating;

If you really having some sort of multi-thread problem try this

double temp = tRating;
boolean test = !Double.isNAN(temp);
assert test : ...

This will at least tell you for certain if tRating is getting updated
later, or if something weird is going on with temp and isNaN().
 
D

Daniel Pitts

Mark said:
If you really having some sort of multi-thread problem try this

double temp = tRating;
boolean test = !Double.isNAN(temp);
assert test : ...

This will at least tell you for certain if tRating is getting updated
later, or if something weird is going on with temp and isNaN().

Just to be on the safe side:

final double temp = tRating;
final boolean test = !Double.isNaN(temp);

assert test:temp;
 
T

thebad1

Mark said:
If you really having some sort of multi-thread problem try this
().

Lol! It's definitely not multi-threaded, the program is of the form;

main(){
file = open file for processing()
while(items in file){
//do 300 million lines in file
tRaging += pow(item1 * item2 * item3,2)
}
}
System.out.println(Math.sqrt(tRating));

I wouldn't know how to multithread it if I tried... ;-)

Tom
 
P

Patricia Shanahan

thebad1 said:
Mark Space wrote:




Lol! It's definitely not multi-threaded, the program is of the form;

main(){
file = open file for processing()
while(items in file){
//do 300 million lines in file
tRaging += pow(item1 * item2 * item3,2)
}
}
System.out.println(Math.sqrt(tRating));

I wouldn't know how to multithread it if I tried... ;-)

Tom

I assume no graphics during the file processing.

Patricia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top