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.
|