Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Program seems to hang; I can't find the bug  RSS feed

 
Bupjae Lee
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My friend gave me following program and said it doesn't work



When I ran this program, after first println, my program didn't respond, didn't print message (including error message), didn't terminate.
I can't find what is wrong in this program, and I want to spot what and where the bug is.

Thanks in advance.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bupjae Lee wrote:...I want to spot what and where the bug is...

This appears to be a recently discovered bug in Java.

See Java Hangs When Converting 2.2250738585072012e-308.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bupjae Lee wrote:My friend gave me following program and said it doesn't work

Did you ask him where that value came from ?
 
David Byron
Rancher
Posts: 175
Clojure Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a JVM bug based on an oversight in the floating point standards.

Read all about it here or here.
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oracle have fixed this in Java 6u24 already, and have released a patch for older versions.
 
Bupjae Lee
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The conclusion is: There is no wrong point in the code. All I have to do is update my JDK & JRE to the latest patch.
Is it right?

Christophe Verré wrote:Did you ask him where that value came from ?

He said he just found that number from the Internet.
 
Campbell Ritchie
Marshal
Posts: 55751
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know what that value represents? Do you know its binary or hex format?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bupjae Lee wrote:The conclusion is: There is no wrong point in the code. All I have to do is update my JDK & JRE to the latest patch.
Is it right?

Yes, as you can see in the responses above, it's a recently discovered bug in the JDK / JRE.
 
Bupjae Lee
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Result:
2.2250738585072012e-308
2.2250738585072014E-308


After updating my JDK/JRE, program works well. Thanks all.

Campbell Ritchie wrote:Do you know what that value represents? Do you know its binary or hex format?


I don't know exactly... What I know is that float and double can't represent values exactly.
(for example, 1.03-0.97 is not exactly 0.06 for double)
 
Campbell Ritchie
Marshal
Posts: 55751
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to look through the API documentation.
 
Bupjae Lee
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is following statement is ture?

This bug was happened because JRE couldn't decide whether value "2.2250738585072012e-308" is
"normalized value" or "de-normalized value".
 
Campbell Ritchie
Marshal
Posts: 55751
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess that's how you could summarize what's happening.

If you want to know the exact details of the bug, read the article that marc already posted a link to above:

marc weber wrote:
Bupjae Lee wrote:...I want to spot what and where the bug is...

This appears to be a recently discovered bug in Java.

See Java Hangs When Converting 2.2250738585072012e-308.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!