Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / January 2007

Tip: Looking for answers? Try searching our database.

Why is this assertion being triggered?

Thread view: 
thebad1 - 08 Jan 2007 11:52 GMT
I have the following line in my code, which hits on the assertion and
causes an error...

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

Exception in thread "main" java.lang.AssertionError:
!Double.isNaN(tRating), tRating=0.008022550661971689
    at packages.Netflix.predictRating(Netflix.java:224)
    at packages.Netflix.main(Netflix.java:150)

But you can see from the output that the tRating variable is a number,
and should not trigger...

Any ideas on this one would be appreciated.

Thanks,

T.
Eric Sosman - 08 Jan 2007 13:39 GMT
> I have the following line in my code, which hits on the assertion and
> causes an error...
[quoted text clipped - 9 lines]
> But you can see from the output that the tRating variable is a number,
> and should not trigger...

    Are you sure you're looking at line 224, and not at some
other similar `assert' elsewhere in the code?  Perhaps an
`assert' that is missing the initial `!'?

Signature

Eric Sosman
esosman@acm-dot-org.invalid

thebad1 - 08 Jan 2007 14:03 GMT
>      Are you sure you're looking at line 224, and not at some
> other similar `assert' elsewhere in the code?  Perhaps an
> `assert' that is missing the initial `!'?

I'm pretty sure. The line gets highlighted in eclipse debugger, and I
can see it at line 224 in the code...

It doesn't hit every time, which is another odd thing. Sometimes its a
different line.
Tom Hawtin - 08 Jan 2007 16:13 GMT
> I'm pretty sure. The line gets highlighted in eclipse debugger, and I
> can see it at line 224 in the code...
>
> It doesn't hit every time, which is another odd thing. Sometimes its a
> different line.

Can you write a reproducible test case. The following code works for me.

class No {
    public static void main(String[] args) {
        double value = 0.008022550661971689;
        assert !Double.isNaN(value);
    }
}

Tom Hawtin
Eric Sosman - 08 Jan 2007 16:56 GMT
thebad1 wrote On 01/08/07 09:03,:

>>     Are you sure you're looking at line 224, and not at some
>>other similar `assert' elsewhere in the code?  Perhaps an
[quoted text clipped - 5 lines]
> It doesn't hit every time, which is another odd thing. Sometimes its a
> different line.

   A different `assert' line, I suppose?

   Well, on to my second guess -- and this one is *really*
shaky!  Is your program multi-threaded?  If so, is it possible
that two or more threads are mucking with the `tRating' variable
at the same time, without proper synchronization?

   If neither guess pans out, I'm out of ideas.

Signature

Eric.Sosman@sun.com

thebad1 - 08 Jan 2007 19:29 GMT
>     Well, on to my second guess -- and this one is *really*
> shaky!  Is your program multi-threaded?  If so, is it possible
> that two or more threads are mucking with the `tRating' variable
> at the same time, without proper synchronization?
>
>     If neither guess pans out, I'm out of ideas.

It's not threaded, just that main class running alone.

I'm out of ideas too, I'm getting a one way ticket to Bonkersville if I
think about this any more... ;-(
thebad1 - 08 Jan 2007 19:34 GMT
> > different line.
>
>     A different `assert' line, I suppose?

I think its interesting that if I "drop to frame" in the debugger and
run by that again, the assert does not trigger. There is it would seem
some sort of non-deterministic issue in play.

The next interesting thing, is that I can run the same class on my
target machine, which is RHEL 3 ES on x86, and I do not see any of the
same assert hits that I do on the winXP dev box. (This is running
exactly the same code)

I can replicate the problem with various JRE and JDK on windows, and
using different debuggers and from command line.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.