Hi All,
Does SimpleDateFormat have any dependency on JDK versions?
I am encountering the following issue:
I have a
java file named as Constants.java. The contents of this file is as follows:
package com.test.util;
import java.text.SimpleDateFormat;
/**
* Class that contains
string contants that can be used in other classes.
*
*/
public final class Constants {
// Logging messages
public final static String TRACK = "FCLPLM000000";
public final static String METHOD_BEGIN = "in";
public final static String METHOD_END = "out";
public final static String METHOD_INSIDE = "inside";
// Exception messages
public final static String ENVIRONMENT_FILE_NOT_FOUND = "FCLEAI000001";
public final static String ENVIRONMENT_FIELD_NOT_FOUND = "FCLEAI000002";
public final static SimpleDateFormat staffwareDateFormatter = new SimpleDateFormat("dd/MM/yyyy");
public final static SimpleDateFormat stafwfareTimeFormatter = new SimpleDateFormat("HH:mm");
public final static SimpleDateFormat xmlTimeStampFormatter = new SimpleDateFormat("yyyy/MM/ddTHH:mm:ss");
}
This class is being referenced by another class InitialProcessor.java
Given below is a code snippet of the same:
package com.test.processor;
import java.math.BigDecimal;
import java.util.*;
import com.test.util.Constants;
public class InitialProcessor{
public static void main(String[] args) {
try {
System.out.println("Inside Try");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date todayDate = new Date();
System.out.println("Before formating");
String strDate = dateFormat.format(todayDate);
System.out.println("Today: " + strDate);
String strDateConst = Constants.staffwareDateFormatter.format(todayDate);
System.out.println("Today from Const: " + strDateConst);
System.out.println("After formating");
} catch (Throwable e){
System.out.println("Inside exception");
e.printStackTrace();
}
}
}
When I run the above code on AIX 5.2 machine with JDK 1.4.2, I get the following output:
wasusr02@UIT-MCP-WEB8:/data/was5-2#/appl/was51/java/bin/java TestSimpleDateFormat
Inside Try
Before formating
Today: 18/10/2007
Inside exception
java.lang.ExceptionInInitializerError
at TestSimpleDateFormat.main(TestSimpleDateFormat.java:33)
Caused by: java.lang.IllegalArgumentException: Illegal
pattern character 'T'
at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:700)
at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:513)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:462)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:443)
at Constants.<clinit>(Constants.java:27)
... 1 more
wasusr02@UIT-MCP-WEB8:/data/was5-2#
The following line in the code: String strDateConst = Constants.staffwareDateFormatter.format(todayDate);
causes the Throwable error.
When I run the same on AIX 5.1 machine with JDK 1.3.1 , everything works fine.
Can anyone please throw some light on what is happening? Are there any JDK dependencies?
Thanks in Advance,
Anup
[ October 18, 2007: Message edited by: Anup Bansal ]