JDK-6315903 : java.text.SimpleDateFormat.format(java.util.Date d) works uncorrectly in some cases
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2005-08-25
  • Updated: 2012-03-23
  • Resolved: 2005-09-12
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
6Resolved
Related Reports
Duplicate :  
Description
JCK 6.0 b06 test api/java_sql/Timestamp/descriptions.html#Ctor[Timestamp1008] failed
on mustang b48, windows 2000 Pro, x86. ( passed on mustang b47 ).
This test creates several timestamps and compares it with expected results. It uses
toString() for Timestamp t vars, 
java.text.SimpleDateFormat.format(java.util.Data d) for expected value and compares
results as strings ( see full test source in attach && extract from test below ):
----------------------------------------
--Test fragment-( see original && modified for standalone testing in attach )-------- 
boolean matches(java.util.Date d, int nanos, Timestamp t) {
      boolean result;
      String s = t.toString();       
      java.text.SimpleDateFormat formatter = new 
      java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.", java.util.Locale.US);
      formatter.setTimeZone(java.util.TimeZone.getDefault());
      // add leading zeros
      String expected = ""+nanos;
      while (expected.length()<9)
        expected="0"+expected;
      // format date
// Passed with uncommented string below !!!
//      d.toString();
      expected = formatter.format(d)+expected;
      // remove trailing zeros
      int i; for (i=expected.length()-1; expected.charAt(i)=='0'; i--);
      if (expected.charAt(i)=='.')  i++;
      expected=expected.substring(0,i+1);
      result=s.equals(expected);    
//      if (!result) {
        System.out.println("\ntime stamp created : [" + s + "]");
        System.out.println("time stamp expected: [" + expected + "]");
//      }
      return result;
}
--------------------------------------------------
--------------------------------------------------
Comment:
Test failed with timestamps values created as new Timestamp(Long.MAX_VALUE),
 new Timestamp(Long.MAX_VALUE-1), Timestamp(Long.MIN_VALUE), Timestamp(Long.MIN_VALUE+1).
But test will be passed if we add only string:
  d.toString();
before
  expected = formatter.format(d)+expected;
So java.text.SimpleDateFormat.format(d) method probably trying to use internal results of
 d.toString() call and it may cause problems if method misses it for work with boundary
 values.
------------------------------------
How to reproduce: 
Compile && run on mustang b47, b48 CtorTests.java from attach
try to uncomment string and see results
// ZZZ: For test passing:
//     d.toString();
------------------------------------
Standard JCK test output:

#Test Results (version 2)
#Tue Aug 23 18:28:58 MSD 2005
#checksum:dab15eb8e0d752d
#-----testdescription-----
$file=Z:\\Links\\stt\\jck_promotions\\6.0\\beta\\b06\\binaries\\JCK-runtime-60\\tests\\api\\java_sql\\Timestamp\\descriptions.html
$root=Z:\\Links\\stt\\jck_promotions\\6.0\\beta\\b06\\binaries\\JCK-runtime-60\\tests
executeArgs=-TestCaseID ALL
executeClass=javasoft.sqe.tests.api.java.sql.Timestamp.CtorTests
id=Ctor
keywords=positive runtime
source=CtorTests.java
title=Timestamp constructor test

#-----environment-----
command.testExecute=com.sun.jck.lib.ExecJCKTestOtherJVMCmd PATH=Z:\\Links\\stt\\jck_promotions\\6.0\\beta\\b06\\binaries\\JCK-runtime-60\\lib\\win32;Z:\\Links\\stt\\jck_promotions\\6.0\\beta\\b06\\binaries\\JCK-runtime-60\\lib\\win32\\jmx;Z:\\Links\\stt\\jck_promotions\\6.0\\beta\\b06\\binaries\\JCK-runtime-60\\lib\\win32 SystemRoot=C:/WINNT TMP=Z:\\Links\\stt\\jck_workspace\\mustang\\b48\\jck\\Win2000-server-Xmixed-jck-6.0-runtime\\workDir TEMP=Z:\\Links\\stt\\jck_workspace\\mustang\\b48\\jck\\Win2000-server-Xmixed-jck-6.0-runtime\\workDir  Z:\\Links\\stt\\jdk_promotions\\JDK6.0\\b48\\binaries\\windows-i586\\jre1.6.0\\bin\\java.exe -server -Xmixed ${jvmtiAgentOptions} -Xfuture $jdwpAgentOptions -classpath $testSuiteRootDir\\classes $JPLISAgentOpts $JPLISAgent2Opts -Djava.security.policy=$testSuiteRootDir\\lib\\jck.policy $testExecuteClass $testExecuteArgs

#-----testresult-----
description=file:///Z:/Links/stt/jck_promotions/6.0/beta/b06/binaries/JCK-runtime-60/tests/api/java_sql/Timestamp/descriptions.html#Ctor
end=Tue Aug 23 18:28:58 MSD 2005
environment=jck15
execStatus=Failed. test cases: 24; passed: 23; failed: 1; first test case failure: Timestamp1008
javatestOS=Windows 2000 5.0 (x86)
javatestVersion=3.2.1
script=com.sun.jck.lib.JCKScript 
sections=script_messages testExecute
start=Tue Aug 23 18:28:51 MSD 2005
test=api/java_sql/Timestamp/descriptions.html#Ctor
timeoutSeconds=600
work=Z:\\Links\\stt\\jck_workspace\\mustang\\b48\\jck\\Win2000-server-Xmixed-jck-6.0-runtime\\workDir\\api\\java_sql\\Timestamp

#section:script_messages
----------messages:(1/25)----------
Executing test class...

#section:testExecute
----------messages:(1/929)*----------
command: com.sun.jck.lib.ExecJCKTestOtherJVMCmd PATH=Z:\\Links\\stt\\jck_promotions\\6.0\\beta\\b06\\binaries\\JCK-runtime-60\\lib\\win32;Z:\\Links\\stt\\jck_promotions\\6.0\\beta\\b06\\binaries\\JCK-runtime-60\\lib\\win32\\jmx;Z:\\Links\\stt\\jck_promotions\\6.0\\beta\\b06\\binaries\\JCK-runtime-60\\lib\\win32 SystemRoot=C:/WINNT TMP=Z:\\Links\\stt\\jck_workspace\\mustang\\b48\\jck\\Win2000-server-Xmixed-jck-6.0-runtime\\workDir TEMP=Z:\\Links\\stt\\jck_workspace\\mustang\\b48\\jck\\Win2000-server-Xmixed-jck-6.0-runtime\\workDir Z:\\Links\\stt\\jdk_promotions\\JDK6.0\\b48\\binaries\\windows-i586\\jre1.6.0\\bin\\java.exe -server -Xmixed -Xfuture -classpath Z:\\Links\\stt\\jck_promotions\\6.0\\beta\\b06\\binaries\\JCK-runtime-60\\classes -Djava.security.policy=Z:\\Links\\stt\\jck_promotions\\6.0\\beta\\b06\\binaries\\JCK-runtime-60\\lib\\jck.policy javasoft.sqe.tests.api.java.sql.Timestamp.CtorTests -TestCaseID ALL
----------out1:(25/791)----------
Timestamp0001: Passed. OKAY
Timestamp0002: Passed. OKAY
Timestamp0003: Passed. OKAY
Timestamp0004: Passed. OKAY
Timestamp0005: Passed. OKAY
Timestamp0006: Passed. OKAY
Timestamp0007: Passed. OKAY
Timestamp0008: Passed. OKAY
Timestamp0009: Passed. OKAY
Timestamp0010: Passed. OKAY
Timestamp0011: Passed. OKAY
Timestamp0012: Passed. OKAY
Timestamp0013: Passed. OKAY
Timestamp0014: Passed. OKAY
Timestamp1001: Passed. OKAY
Timestamp1002: Passed. OKAY
Timestamp1003: Passed. OKAY
Timestamp1004: Passed. OKAY
Timestamp1005: Passed. OKAY
Timestamp1006: Passed. OKAY
Timestamp1007: Passed. OKAY
Timestamp0015: Passed. OKAY
Timestamp0016: Passed. OKAY
Timestamp1008: Failed. Failed
STATUS:Failed.test cases: 24; passed: 23; failed: 1; first test case failure: Timestamp1008
----------out2:(3/133)----------
time stamp created : [292272993-01-04 10:12:55.807]
time stamp expected: [292278994-08-17 10:12:55.807]
tm  = 9223372036854775807
result: Failed. test cases: 24; passed: 23; failed: 1; first test case failure: Timestamp1008


test result: Failed. test cases: 24; passed: 23; failed: 1; first test case failure: Timestamp1008

Comments
EVALUATION This is a duplicate of 6314387.
12-09-2005