Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4755500
Votes 2
Synopsis REGRESSION: calling Math.round(NaN) can break subsequent calls to Math.round()
Category hotspot:compiler1
Reported Against 1.4.1
Release Fixed 1.4.2(mantis)
State 10-Fix Delivered, bug
Priority: 3-Medium
Related Bugs 4760131
Submit Date 30-SEP-2002
Description




FULL PRODUCT VERSION :
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)


FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

ADDITIONAL OPERATING SYSTEMS :

We tested against Linux and Solaris and did not see the bug.


A DESCRIPTION OF THE PROBLEM :
After calling Math.round(double) a number of times,
including some calls to Math.round(Double.NaN), subsequent
calls to Math.round(double) may incorrectly return 0.

There are a number of ways to reproduce this, but the
easiest thing to do is just to call Math.round(Double.NaN)
2000 times.  The next time you call Math.round(double) the
result will always be 0, regardless of what you supply as
an argument.

Math.round(float) seems to be affected also.


REGRESSION.  Last worked in version 1.4

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Make 2000 calls to Math.round(Double.NaN)
2. Make one call to Math.round(double) using a whole number
argument (e.g. 1d or 12345d)


EXPECTED VERSUS ACTUAL BEHAVIOR :
The result is 0 when it should be equal to the argument
(e.g. 1 or 12345)

ERROR MESSAGES/STACK TRACES THAT OCCUR :
We discovered this bug after experiencing the following two exceptions during
calls to Graphics.drawLine() somewhere inside the paint method of one of our
components:

sun.dc.pr.PRException: endPath: bad path
        at sun.dc.pr.Rasterizer.endPath(Rasterizer.java:537)
        at sun.java2d.pipe.DuctusRenderer.createShapeRasterizer
(DuctusRenderer.java:374)
        at sun.java2d.pipe.DuctusShapeRenderer.renderPath
(DuctusShapeRenderer.java:57)
        at sun.java2d.pipe.DuctusShapeRenderer.draw(DuctusShapeRenderer.java:45)
        at sun.java2d.pipe.PixelToShapeConverter.drawLine
(PixelToShapeConverter.java:34)
        at sun.java2d.SunGraphics2D.drawLine(SunGraphics2D.java:1954)
        ...



sun.dc.pr.PRError: setPenT4: invalid pen transformation (singular)
        at sun.dc.pr.PathStroker.setPenT4(Native Method)
        at sun.dc.pr.Rasterizer.setPenT4(Rasterizer.java:205)
        at sun.java2d.pipe.DuctusRenderer.createShapeRasterizer
(DuctusRenderer.java:260)
        at sun.java2d.pipe.DuctusShapeRenderer.renderPath
(DuctusShapeRenderer.java:57)
        at sun.java2d.pipe.DuctusShapeRenderer.draw(DuctusShapeRenderer.java:45)
        at sun.java2d.pipe.PixelToShapeConverter.drawLine
(PixelToShapeConverter.java:34)
        at sun.java2d.SunGraphics2D.drawLine(SunGraphics2D.java:1954)
        ...


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class MathBugTest {
  
  public static void main(String[] args) {
    System.out.println(Math.round(1d));  // prints "1", as expected
    for (int i=0; i<2000; i++) {
      Math.round(Double.NaN);
    }
    System.out.println(Math.round(1d));  // prints "0", which is wrong
  }
  
}
---------- END SOURCE ----------

CUSTOMER WORKAROUND :
Hack the java.lang.Math.round(float/double) methods so that
they test for NaN prior to calling StrictMath.round()

Release Regression From : 1.4.0_02
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Review ID: 165064) 
======================================================================
Work Around
N/A
Evaluation
This is a bug in the d2l conversion stub which was introduced for speed in
1.4.1. In the NaN case we weren't popping the argument off the FPU stack, which
for some reason caused subsequent flds to be messed up. Will be fixed in 1.4.2
and recommended to be backported to 1.4.1_02.

 xxxxx@xxxxx  2002-10-04

Revised test case with pass/fail result:
public class MathBugTest {
  public static void main(String[] args) {
    // Note: it's really only necessary to run this loop 8 times to
    // reproduce the bug, but the 2000-length loop causes compilation
    // of Math.round() without any other command-line flags.
    // A bug in the d2l NaN case was causing overflow of the FPU
    // stack, yielding subsequent wrong results for flds.
    for (int i=0; i<2000; i++) {
        Math.round(Double.NaN);
    }
    if (Math.round(1d) != 1) {
        throw new RuntimeException("TEST FAILED");
    }
    System.out.println("Test passed.");
  }
}

 xxxxx@xxxxx  2002-10-04
Comments
  
  Include a link with my name & email   

Submitted On 15-SEP-2003
Rick.Jelliffe
I have this bug using Java 1.4.2_3 both on Linux and Windows
2000.


Submitted On 30-SEP-2003
hbkou
Can anybody reopen this issue? I am using jfreechart to draw 
analysis chart and encounter this problem several times. By 
the way my JDK version is 1.4.2-b28.

Thanks


Submitted On 10-NOV-2003
jhing01
This indeed is still a problem with 1.4.2  I'm using a 3rd party 
charting package, Ilog Jviews. Turning off anti-aliasing seems 
to be a workaround, although now the graphs don't look as 
nice.

Please fix !


Submitted On 10-DEC-2003
vk2
I can confirm this bug for JDK 1.4.2_b28.  The first line of
the stacktrace is: 
sun.dc.pr.PRException: endPath: bad path


Submitted On 11-DEC-2003
xspyro_screen
I have this bug also with NetCharts Lib. But turning 
OFF Antialiasing won't help.


Submitted On 11-DEC-2003
neverever
Please, if you are going to add comments saying that you are
also seeing the problem please provide more detail than
simply saying "me too".  At  a minimum you need to provde a
contact address.  If you are concerned about putting your
email address in  a public forum then I would request you
submit a bug report using
http://java.sun.com/webapps/bugreport/ and include some more
information about the problem.  If there is an issue we'd
really like to fix it.


Submitted On 25-MAY-2004
adeane1
We're getting this problem on intel pc's. We've tried 1.4.2_04 and it doesn't fix it. So what release is it fixed in?


Submitted On 14-JUN-2005
seraph
This is bug is still exist in Java 1.4.2_7.
I was using JfreeChart and Cewolf.
Then, it occured.



PLEASE NOTE: JDK6 is formerly known as Project Mustang