Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 260079

Summary: float value is incorrectly parsed
Product: [Eclipse Project] JDT Reporter: Mike . <eclipse.spam.magnet>
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: CLOSED NOT_ECLIPSE QA Contact:
Severity: normal    
Priority: P3 CC: darin.eclipse, tim.bell
Version: 3.4.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
screenshot of debug session
none
screen shot of correct behavior none

Description Mike . CLA 2009-01-06 13:34:19 EST
Created attachment 121668 [details]
screenshot of debug session

This code:
----------------------------------------------------------------------
public class Test {
    public static void main( String[] args ) {
        double d = 165.5429477620094;
        float f = (float) d;
        System.out.println( d );
        System.out.println( f );
        System.out.println( Float.toString( f ) );
    }
}
----------------------------------------------------------------------

outputs:
----------------------------------------------------------------------
165.5429477620094
165.54295
165.54295
----------------------------------------------------------------------

but the float value is displayed in the Variables and pop-up windows as 165.79295.
Comment 1 Darin Wright CLA 2009-01-07 12:57:47 EST
This appears to be a VM bug. When I debug against a Sun VM (any version I have), I see this error. When I debug against an IBM 6.0 SR3 VM I see the correct value for the variable in the variables view. We are simply using a DataInputStream to read the float value:

public float readFloat(String description, DataInputStream in) throws IOException {
	float result = in.readFloat();
	if (fVerboseWriter != null) {
		fVerboseWriter.println(description, result);
	}
	return result;
}

The int value (4 bytes) returned by JDI in the error case is 1126550271, and in the correct case is 1126533887, which is converted to the float seen in the variables view.
Comment 2 Darin Wright CLA 2009-01-07 12:59:08 EST
Created attachment 121835 [details]
screen shot of correct behavior
Comment 3 Darin Wright CLA 2009-01-07 13:07:04 EST
Marking as not Eclipse.
Comment 4 Mike . CLA 2009-01-08 18:37:59 EST
Verified on the test code using the Sun jdb:
----------------------------------------------------------------------
>jdb Test
Initializing jdb ...
> stop at Test:5
Deferring breakpoint Test:5.
It will be set after the class is loaded.
> run
run Test
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started: Set deferred breakpoint Test:5

Breakpoint hit: "thread=main", Test.main(), line=5 bci=7
5            System.out.println( d );

main[1] print d
 d = 165.5429477620094
main[1] print f
 f = 165.79295
main[1] cont
> 165.5429477620094
165.54295
165.54295

The application exited

----------------------------------------------------------------------

Submitted to SDN, internal review ID is 1430436.
Comment 5 Mike . CLA 2009-01-08 18:39:05 EST
Bug is in the Sun JDK.
Comment 6 tim.bell CLA 2009-02-19 15:38:15 EST
I reproduced this using JDK 1.7.0-ea-b42 on OpenSolaris 2008.11

I filed Sun Bug-ID 6807341

After a few more working days (I don't control that web site... sorry) this report will be visible here:

   http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6807341

Turning on JDWP verbose tracing during a jdb session shows the wrong value is coming across the wire from the VM, so the problem is in JDWP or below that:





% cat -n Test.java
     1  public class Test {
     2      public static void main( String[] args ) {
     3          double d = 165.5429477620094;
     4          float f = (float) d;
     5          System.out.println( d );
     6          System.out.println( f );
     7          System.out.println( Float.toString( f ) );
     8      }
     9  }

% javac -g Test.java
% jdb -J-showversion -dbgtrace 0x00ffffff Test 
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b42)
Java HotSpot(TM) Server VM (build 14.0-b09, mixed mode)

Initializing jdb ...
> stop at Test:7
Deferring breakpoint Test:7.
It will be set after the class is loaded.
> run
        [ ... SNIP ... ]

main[1] print f
[JDI: Sending Command(id=444) JDWP.Method.VariableTableWithGeneric]
[JDI: Sending:                 refType(ReferenceTypeImpl): ref=371]
[JDI: Sending:                 methodID(long): 135598416]
[JDI: Receiving Command(id=444) JDWP.Method.VariableTableWithGeneric]
[JDI: Receiving:                argCnt(int): 1]
[JDI: Receiving:                slots(SlotInfo[]): ]
[JDI: Receiving:                    slots[i](SlotInfo): ]
[JDI: Receiving:                    codeIndex(long): 0]
[JDI: Receiving:                    name(String): args]
[JDI: Receiving:                    signature(String): [Ljava/lang/String;]
[JDI: Receiving:                    genericSignature(String): ]
[JDI: Receiving:                    length(int): 32]
[JDI: Receiving:                    slot(int): 0]
[JDI: Receiving:                    slots[i](SlotInfo): ]
[JDI: Receiving:                    codeIndex(long): 4]
[JDI: Receiving:                    name(String): d]
[JDI: Receiving:                    signature(String): D]
[JDI: Receiving:                    genericSignature(String): ]
[JDI: Receiving:                    length(int): 28]
[JDI: Receiving:                    slot(int): 1]
[JDI: Receiving:                    slots[i](SlotInfo): ]
[JDI: Receiving:                    codeIndex(long): 7]
[JDI: Receiving:                    name(String): f]
[JDI: Receiving:                    signature(String): F]
[JDI: Receiving:                    genericSignature(String): ]
[JDI: Receiving:                    length(int): 25]
[JDI: Receiving:                    slot(int): 3]
[JDI: Sending Command(id=446) JDWP.StackFrame.GetValues]
[JDI: Sending:                 thread(ThreadReferenceImpl): ref=1]
[JDI: Sending:                 frame(long): 196608]
[JDI: Sending:                 slots(SlotInfo[]): ]
[JDI: Sending:                     slots[i](SlotInfo): ]
[JDI: Sending:                     slot(int): 3]
[JDI: Sending:                     sigbyte(byte): 70]
[JDI: Receiving Command(id=446) JDWP.StackFrame.GetValues]
[JDI: Receiving:                values(ValueImpl[]): ]
[JDI: Receiving:                    values[i](ValueImpl): 165.79295]
 f = 165.79295

main[1] locals
[JDI: Sending Command(id=450) JDWP.StackFrame.GetValues]
[JDI: Sending:                 thread(ThreadReferenceImpl): ref=1]
[JDI: Sending:                 frame(long): 196608]
[JDI: Sending:                 slots(SlotInfo[]): ]
[JDI: Sending:                     slots[i](SlotInfo): ]
[JDI: Sending:                     slot(int): 0]
[JDI: Sending:                     sigbyte(byte): 91]
[JDI: Sending:                     slots[i](SlotInfo): ]
[JDI: Sending:                     slot(int): 1]
[JDI: Sending:                     sigbyte(byte): 68]
[JDI: Sending:                     slots[i](SlotInfo): ]
[JDI: Sending:                     slot(int): 3]
[JDI: Sending:                     sigbyte(byte): 70]
[JDI: Receiving Command(id=450) JDWP.StackFrame.GetValues]
[JDI: Receiving:                values(ValueImpl[]): ]
[JDI: Creating new com.sun.tools.jdi.ArrayReferenceImpl (id = 419)]
[JDI: Sending Command(id=452) JDWP.ObjectReference.ReferenceType]
[JDI: Sending:                 object(ObjectReferenceImpl): ref=419]
[JDI: Receiving Command(id=452) JDWP.ObjectReference.ReferenceType]
[JDI: Receiving:                refTypeTag(byte): 3]
[JDI: Receiving:                typeID(long): ref=125]
[JDI: Looking up ArrayType, id=125]
[JDI: Sending Command(id=454) JDWP.ArrayReference.Length]
[JDI: Sending:                 arrayObject(ArrayReferenceImpl): ref=419]
[JDI: Receiving Command(id=454) JDWP.ArrayReference.Length]
[JDI: Receiving:                arrayLength(int): 0]
[JDI: Receiving:                    values[i](ValueImpl): instance of java.lang.String[0] (id=419)]
[JDI: Receiving:                    values[i](ValueImpl): 165.5429477620094]
[JDI: Receiving:                    values[i](ValueImpl): 165.79295]
Method arguments:
args = instance of java.lang.String[0] (id=419)
Local variables:
d = 165.5429477620094
f = 165.79295

main[1] cont
[JDI: Sending Command(id=456) JDWP.VirtualMachine.Resume]
[JDI: Clearing VM suspended cache]
[JDI: Clearing temporary cache for ThreadReference 1]
[JDI: Clearing temporary cache for ThreadReference 290]
[JDI: Clearing temporary cache for ThreadReference 291]
[JDI: Clearing temporary cache for ThreadReference 292]
[JDI: Receiving Command(id=456) JDWP.VirtualMachine.Resume]
> 165.54295

NOTE: "System.out.println( f );" gives "165.54295"