JDK-6817065 : Parameter passed to Applet is not trimmed for spaces in JDK 1.6
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 6u10
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2009-03-13
  • Updated: 2011-02-16
  • Resolved: 2009-08-19
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 JDK 7
6u18 b01Fixed 7Fixed
Description
FULL PRODUCT VERSION :
JDK 1.6

ADDITIONAL OS VERSION INFORMATION :
Windows XP/2000

A DESCRIPTION OF THE PROBLEM :
In all versions prior to 1.6.0, getParameter returns the parameter value without whitespace (spaces, tabs and line feeds). This causes problems when for example the value is tokenized and tokens are not trimmed in code.

Insert line feeds to param value, then use getParameter to get the value.

For example:

<applet code="ParamTest.class" width="200" height="200">
	<param name="numbers" value="
5\1015\2025\30">
</applet>

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
5
10
15
20
25
30
ACTUAL -
5
10
java.lang.NumberFormatException: For input string: "
	15"
	at java.lang.NumberFormatException.forInputString(Unknown Source)
	at java.lang.Integer.parseInt(Unknown Source)
	at java.lang.Integer.parseInt(Unknown Source)
	at ParamTest.start(ParamTest.java:11)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NumberFormatException: For input string: "
	15"

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NumberFormatException: For input string: "
	15"
	at java.lang.NumberFormatException.forInputString(Unknown Source)
	at java.lang.Integer.parseInt(Unknown Source)
	at java.lang.Integer.parseInt(Unknown Source)
	at ParamTest.start(ParamTest.java:11)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NumberFormatException: For input string: "
	15"
code: import java.applet.Applet;
import java.util.StringTokenizer;

public class ParamTest extends Applet
{
	public void start()
	{
		StringTokenizer st = new StringTokenizer(getParameter("numbers"), "\\");
		while (st.hasMoreTokens())
		{
			System.out.println(Integer.parseInt(st.nextToken()));
		}
	}
}

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the applet .

Read the parameter which is having new line char in HTML.
All new line character was remove till JDk 1.5 ,in 1.6 new line is not removed
and the code through an exception

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
All new line character should be  removed in 1.6
and the code should work
ACTUAL -
Code through exception in 1.6

ERROR MESSAGES/STACK TRACES THAT OCCUR :
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NumberFormatException: For input string: "
	15"
	at java.lang.NumberFormatException.forInputString(Unknown Source)
	at java.lang.Integer.parseInt(Unknown Source)
	at java.lang.Integer.parseInt(Unknown Source)
	at ParamTest.start(ParamTest.java:11)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NumberFormatException: For input string: "
	15"
code: import java.applet.Applet;

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaparser;

import java.applet.Applet;
import java.util.StringTokenizer;

public class ParamTest extends Applet
{
	public void start()
	{
		//StringTokenizer st = new StringTokenizer(getParameter("numbers"), "\\ \t\n\r\f");
StringTokenizer st = new StringTokenizer(getParameter("numbers"), "\\");
		while (st.hasMoreTokens())
		{
            String token=st.nextToken();
            System.out.println(token);
			System.out.println(Integer.parseInt(token));
		}
	}
}



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

CUSTOMER SUBMITTED WORKAROUND :
<!--
  To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    TODO write content
  </body>
  <applet code="javaparser.ParamTest.class" width="200" height="200">
<param name="numbers" value="5\1015\2025\30">
      </applet>
</html>

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

Comments
EVALUATION I am not quite sure I understand the bug description correctly. However, I did compare the old plugin and new plugin (new plugin is introduced in 6u10). There is a difference when deal with whitespaces inside a parameter. Both plugins trim leading and trailing white spaces. The old plugin, in addition, filters out any '\t' '\n' '\f' '\r' inside the string. So if a parameter is " 5\10 15\20 25\30" In the old plugin, you get "5\1015\2025\30". In the new plugin, you get "5\10 15\20 25\30" When use "\\" to tokenize the string and parse them as integer, NumberFormatException is thrown by parsing "10 15"
17-03-2009