Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6610730
Votes 0
Synopsis [Fmt-Da] java.text.SimpleDateFormat.parse method does not works thread safe
Category java:classes_text
Reported Against
Release Fixed
State 11-Closed, duplicate of 4264153, bug
Priority: 4-Low
Related Bugs
Submit Date 28-SEP-2007
Description
FULL PRODUCT VERSION :
1.6.0_01

ADDITIONAL OS VERSION INFORMATION :
XP professional 2002 with service pack 2


A DESCRIPTION OF THE PROBLEM :
java.text.SimpleDateFormat.parse method does not works thread safe.

when i want to use single instance of SimpleDateFormat class for multi thread
 applications, sometimes .parse method throws excetion......



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
executable code block can be use for



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
when i want to use this class as singleton i should not got exceptions
ACTUAL -
i got exceptions ....

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NumberFormatException: For input string: ""
	at java.lang.NumberFormatException.forInputString(Unknown Source)
	at java.lang.Long.parseLong(Unknown Source)
	at java.lang.Long.parseLong(Unknown Source)
	at java.text.DigitList.getLong(Unknown Source)
	at java.text.DecimalFormat.parse(Unknown Source)
	at java.text.SimpleDateFormat.subParse(Unknown Source)
	at java.text.SimpleDateFormat.parse(Unknown Source)
	at java.text.DateFormat.parse(Unknown Source)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.text.SimpleDateFormat;

public class alll {
	public static void main(String[] args) throws Exception {
		SimpleDateFormat simpleDateFormat =  new SimpleDateFormat("ddMMyyyyHHmm" ) ;
		Tester[] tester = new Tester[10];
		for (int i = 0; i < 10; i++) {
			
			tester[i]  =  new Tester(simpleDateFormat);
			tester[i].start();
			
		}
	}
	/**
	 *
	 */
	private static class Tester extends Thread{
		SimpleDateFormat sp = null;
		public Tester(SimpleDateFormat simpleDateFormat ){
			this.sp = simpleDateFormat;
		}
		public void run(){
			while(true){
				try {
					System.out.println(sp.parse("010120070101"));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}

	}
}
---------- END SOURCE ----------
Posted Date : 2007-09-28 05:19:41.0
Work Around
N/A
Evaluation
N/A
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang