JDK-4401148 : ClassCastException when casting from TimeZone to SimpleTimeZone
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic,solaris_8,windows_nt
  • CPU: generic,x86,sparc
  • Submitted: 2001-01-02
  • Updated: 2001-01-09
  • Resolved: 2001-01-09
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
While attempting to verify bug: 4300378, I came across the following exception. It starts at Merlin-beta b45.

----------------------------------------------------------
Exception in thread "main" java.lang.ClassCastException: sun.util.calendar.ZoneInfo
        at GetDSTSavingsTest.<init>(GetDSTSavingsTest.java:8)
        at GetDSTSavingsTest.main(GetDSTSavingsTest.java:17)
----------------------------------------------------------

The following program reproduces it:

----------------------------------------------------------
import java.util.*;

public class GetDSTSavingsTest {

    SimpleTimeZone stz;

    public GetDSTSavingsTest() {
        stz = (SimpleTimeZone)TimeZone.getTimeZone("Asia/Tokyo");

        System.out.println("Observes daylight savings time? " +
                           stz.useDaylightTime());
        System.out.println("Daylight savings time value(should be 0 if not " +
                           "observed): " + stz.getDSTSavings());
    }

    public static void main(String[] args) {
        new GetDSTSavingsTest();
    }
}
----------------------------------------------------------


edmund.lou@eng 2001-01-02
===================================

Comments
EVALUATION This is not a bug. The result type of TimeZone.getTimeZone is TimeZone, not SimpleTimeZone, and casting the result to SimpleTimeZone therefore obviously creates the risk of a ClassCastException. However, since the J2RE didn't have any TimeZone subclasses other than SimpleTimeZone before Merlin (RFE 4230123), it's possible that more applications will run into this problem. I'm leaving this bug open for the time being to see how many applications are affected. norbert.lindenberg@Eng 2001-01-03 I prefer to close this particular QA bug report because the API change was explicitly approved by the QA team (through the CCC review process). I agree that we should be careful about this compatibility issue for user applications. masayoshi.okutsu@Eng 2001-01-09
09-01-2001