• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Rancher
Posts: 175
Clojure Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22683
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 76440
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you know what that value represents? Do you know its binary or hex format?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76440
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76440
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic