JDK-6741935 : A number passed from JavaScript to Applet become an invalid number format
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 6u10
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2008-08-27
  • Updated: 2011-02-16
  • Resolved: 2008-10-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6u10 b33Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
JRE 1.6.0_10-rc

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
We have an method in applet that process a number passed from JavaScript. It worked fine in previous version of JRE but has java.lang.NumberFormatException in JRE 1.6.0_10-RC

We found that a number 1219224288742 in JavaScript becomes 1.219224288742E12 in our Applet. When we parse it into Long, it has error.

This is not the case in previous version of JRE including 1.6.0_7

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Prepare and compile a Java Applet as follows,

import java.applet.Applet;

public class TestApplet extends Applet {
  public void init() {
    ;
  }

  public void destroy() {
	;
  }

  public void printStringValue(String strValue) {
    System.out.println("strValue: [" + strValue + "]");
  }
}

2. Prepare a HTML as follows,
<html><head><title>ABC</title></head>
<applet code="TestApplet.class" name="test" width="1" height="1"></applet>
<script language="JavaScript">
<!--
	var m_currTime = null;
	m_currTime = new Date().getTime();
	alert("m_currTime: " + m_currTime);

	test.printStringValue(m_currTime);
//-->
</script>
<body>
	TEST
</body>
</html>

3. Run the HTML in web browser


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The number display in the Java Console should has the same format as that prompted in JavaScript.

e.g.:
strValue: [1219224288742]


ACTUAL -
The number display in the Java Console has different format as that prompted in JavaScript.

e.g.:
strValue: [1.219224086554E12]


ERROR MESSAGES/STACK TRACES THAT OCCUR :
The number format is wrong and induces problem if we further process the value.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
TestApplet.java

import java.applet.Applet;

public class TestApplet extends Applet {
  public void init() {
    ;
  }

  public void destroy() {
	;
  }

  public void printStringValue(String strValue) {
    System.out.println("strValue: [" + strValue + "]");
  }
}

=================

testApplet.html

<html><head><title>ABC</title></head>
<applet code="TestApplet.class" name="test" width="1" height="1"></applet>
<script language="JavaScript">
<!--
	var m_currTime = null;
	m_currTime = new Date().getTime();
	alert("m_currTime: " + m_currTime);

	test.printStringValue(m_currTime);
//-->
</script>
<body>
	TEST
</body>
</html>



---------- END SOURCE ----------

Release Regression From : 6u7
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Comments
WORK AROUND Use Double.valueOf(strValue).longValue() to parse the "computerized scientific notation." form string to long.
11-09-2008

EVALUATION The type passed from browser to java plugin is a double (VT_R8 variant type in IE, NPVariantType_Double in mozilla). We convert it to a java Double object. This seems to be right. Old plugin does a NumberFormat parse when converting a number to a string. We will do the same in the new plugin.
11-09-2008