This is the mail archive of the java-patches@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch: PR libgcj/32


This is a new fix for an old bug. The problem is that certain classes in
java.text need to load resources via the URL class loading mechanism.
This mechanism itself uses those java.text classes, and in some cases we
get an ExceptionInInitializerError due to intializer co-dependency. This
patch removes the DateFormat initializers from URLConnection (and
lazy-initializing them instead), which is a simpler and hopefully more
robust fix than hacking the java.text classes themselves.

  [ bryce ]

2000-02-25  Bryce McKinlay  <bryce@albatross.co.nz>

        * java/net/URLConnection.java (initializeDateFormats): New
private
        method.
        (getHeaderFieldDate): Call initializeDateFormats if required.
        locale, dateFormat1, dateFormat2, dateFormat3: Don't initialize
        these.
        Fix for PR libgcj/32.

Index: java/net/URLConnection.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/net/URLConnection.java,v
retrieving revision 1.3
diff -u -r1.3 URLConnection.java
--- URLConnection.java	2000/02/21 05:54:29	1.3
+++ URLConnection.java	2000/02/25 05:24:05
@@ -47,13 +47,10 @@
   private static ContentHandlerFactory factory;
   private static ContentHandler contentHandler;
   private static Hashtable handlers = new Hashtable();
-  private static Locale locale = new Locale("En", "Us", "Unix");
-  private static SimpleDateFormat dateFormat1 =
-	  new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'", locale);
-  private static SimpleDateFormat dateFormat2 =
-	  new SimpleDateFormat("EEEE, dd-MMM-yy hh:mm:ss 'GMT'", locale);
-  private static SimpleDateFormat dateFormat3 =
-	  new SimpleDateFormat("EEE MMM d hh:mm:ss yyyy", locale);
+  private static Locale locale = null; 
+  private static SimpleDateFormat dateFormat1 = null,
+                                  dateFormat2 = null,
+				  dateFormat3 = null;
 
   protected URLConnection(URL url)
   {
@@ -128,6 +125,8 @@
 
   public long getHeaderFieldDate(String name, long val)
   {
+    if (locale == null)
+      initializeDateFormats();
     String str = getHeaderField(name);
     if (str != null)
       {
@@ -436,5 +435,18 @@
     // table for content types that don't have a non-default ContentHandler.
     handlers.put(contentType, contentType);
     return null;
+  }
+  
+  // We don't put these in a static initializer, because it creates problems
+  // with initializer co-dependency: SimpleDateFormat's constructors eventually 
+  // depend on URLConnection (via the java.text.*Symbols classes).
+  private void initializeDateFormats()
+  {
+    locale = new Locale("En", "Us", "Unix");
+    dateFormat1 = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'", 
+                                       locale);
+    dateFormat2 = new SimpleDateFormat("EEEE, dd-MMM-yy hh:mm:ss 'GMT'", 
+                                       locale);
+    dateFormat3 = new SimpleDateFormat("EEE MMM d hh:mm:ss yyyy", locale);
   }
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]