United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6741935 A number passed from JavaScript to Applet become an invalid number format
JDK-6741935 : A number passed from JavaScript to Applet become an invalid number format

Details
Type:
Bug
Submit Date:
2008-08-27
Status:
Closed
Updated Date:
2011-02-16
Project Name:
JDK
Resolved Date:
2008-10-02
Component:
deploy
OS:
windows_xp
Sub-Component:
plugin
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6u10
Fixed Versions:
6u10 (b33)

Related Reports
Relates:

Sub Tasks

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
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.
                                     
2008-09-11
WORK AROUND

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



Hardware and Software, Engineered to Work Together