From 4ae4a3c9739e483a5f2c6c63ec636489f475add6 Mon Sep 17 00:00:00 2001 From: Bryce McKinlay Date: Fri, 25 Feb 2000 22:38:33 +0000 Subject: [PATCH] re GNATS libgcj/38 (Static initializer in DecimalFormat eventually depends on itself) 2000-02-25 Bryce McKinlay * 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/38. From-SVN: r32153 --- libjava/ChangeLog | 9 +++++++++ libjava/java/net/URLConnection.java | 28 +++++++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 6cb290b270f..22f85229320 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,12 @@ +2000-02-25 Bryce McKinlay + + * 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/38. + 2000-02-24 Warren Levy * java/math/BigInteger.java(ival): Made private. diff --git a/libjava/java/net/URLConnection.java b/libjava/java/net/URLConnection.java index a9b42e91601..60cfd76714f 100644 --- a/libjava/java/net/URLConnection.java +++ b/libjava/java/net/URLConnection.java @@ -47,13 +47,9 @@ public abstract class URLConnection 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; + private static SimpleDateFormat dateFormat1, dateFormat2, dateFormat3; + private static boolean dateformats_initialized = false; protected URLConnection(URL url) { @@ -128,6 +124,8 @@ public abstract class URLConnection public long getHeaderFieldDate(String name, long val) { + if (! dateformats_initialized) + initializeDateFormats(); String str = getHeaderField(name); if (str != null) { @@ -437,4 +435,20 @@ public abstract class URLConnection 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 synchronized void initializeDateFormats() + { + if (dateformats_initialized) + return; + 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); + dateformats_initialized = true; + } }