This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 123984 - Step Over inconsistent with Step Into
Summary: Step Over inconsistent with Step Into
Status: REOPENED
Alias: None
Product: debugger
Classification: Unclassified
Component: Code (show other bugs)
Version: 5.x
Hardware: PC Windows XP
: P4 blocker (vote)
Assignee: Martin Entlicher
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-12-13 22:03 UTC by aeriform
Modified: 2007-12-14 19:49 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description aeriform 2007-12-13 22:03:33 UTC
I get a different answer when using step into at the breakpoint than when running or debugging the following program
using step over at the breakpoint.

    public static void main(String[] args){
        //right angle triangle
        double a = Math.sqrt(2.0);
        double b = 1.0;
        double B = Math.PI/4;
        double expResult = Math.PI/2;
Breakpoint-->        double result = getAngle(a, b, B);
        System.out.println(result);
    }

result is NaN when running or using step over at the above breakpoint, but is close (1.5707963118937354) to the correct
value of PI/2 when using step into...

    public static double getAngle(double a, double b, double B){
        double cosine=a*Math.cos(B);
        return Math.acos( Math.sqrt(cosine*cosine+(b-a)*(b+a))/b );
    }

I've tried using Sun JDK 1.5.0_09-b03 and Netbeans 5.5 (Build 200610171010) on Win 2K Pro and Win XP Pro and tried
cleaning and rebuilding, and creating a new file in a new project with the same results.
Comment 1 Martin Entlicher 2007-12-14 17:18:23 UTC
I got always 1.5707963118937354 on Linux when running/debugging/stepping through the program on Linux.
Needs to be explored on Windows... It's likely that the argument to Math.sqrt() gets negative.
Comment 2 aeriform 2007-12-14 18:44:03 UTC
A new day bring clarity...

The following code shows that order of operator values can give different values on both my Win 2K Pro and Win XP Pro
machines. The debugger must rearrange code with the assumption that a*b=b*a which doesn't seem to be true in this case? 

    public static void main(String[] args){
        double anglePair=0.7853981633974483;
        double multiple=1.414213562370951;
        
        double mathCos=Math.cos(anglePair);
        double mathCosMultiple=multiple*mathCos;
        double combinedFormula=multiple*Math.cos(anglePair);
        
        double mathCosMultiple2=mathCos*multiple;
        double combinedFormula2=Math.cos(anglePair)*multiple;
        
        System.out.println("anglePair="+anglePair);
        System.out.println("multiple="+multiple);
        System.out.println("mathCos="+mathCos);
        System.out.println("mathCosMultiple="+mathCosMultiple);
        System.out.println("combinedFormula="+combinedFormula);
        System.out.println("mathCosMultiple2="+mathCosMultiple2);
        System.out.println("combinedFormula2="+combinedFormula2);
    }

gives me the output:

anglePair=0.7853981633974483
multiple=1.414213562370951
mathCos=0.7071067811865476
mathCosMultiple=0.9999999999984841
combinedFormula=0.999999999998484
mathCosMultiple2=0.9999999999984841
combinedFormula2=0.9999999999984841
Comment 3 Martin Entlicher 2007-12-14 18:52:15 UTC
Can you please specify also the processor type, which you have? I've got consistent results on Intel(R) Pentium(R) M
processor 2.00GHz with Linux:

anglePair=0.7853981633974483
multiple=1.414213562370951
mathCos=0.7071067811865476
mathCosMultiple=0.9999999999984841
combinedFormula=0.9999999999984841
mathCosMultiple2=0.9999999999984841
combinedFormula2=0.9999999999984841

If debugger rearranges execution order, it's likely a bug in the JPDA debugger backend. I'll try that on Windows later on. 
Comment 4 Martin Entlicher 2007-12-14 19:00:06 UTC
Ha, I've got it. It's a bug of JDK 1.5. When executed on JDK 1.6 it works fine. But JDK 1.5 produce the described faulty
behavior.
Since it's a JDK bug, we can not fix that in NetBeans.
Use JDK 1.6 as a workaround.
Comment 5 aeriform 2007-12-14 19:43:41 UTC
Actually it seems to be a JRE bug, when compiled with JDK 1.5 and run with JRE 1.6 it works fine...

Why is there an inconsistency in how step into and step over evaluation of code?