[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
String/Hashtable bootstrapping problem
From: |
Eric Blake |
Subject: |
String/Hashtable bootstrapping problem |
Date: |
Fri, 13 Jul 2001 12:07:19 +0100 |
> I have encountered a problem trying to initialize the String and Hashtable
> classes. Here's the problem:
>
> - Hashtable uses String constants like "loadFactor" and "threshold" which
> are initialized in Hashtable.<clinit>.
> - String constants are supposed to have unique values, as ensured
> by String.intern. Thus, for String constant pool entries, I call
> String.intern.
> - String.intern makes use of String.internTable, which is a Hashtable,
> and which is initialized in String.<clinit>.
In a later message,
> I'm talking about these lines from java.util.Hashtable:
>
> // used for serializing instances of this class
> private static final ObjectStreamField[] serialPersistentFields =
> { new ObjectStreamField("loadFactor", float.class),
> new ObjectStreamField("threshold", int.class) };
I'm a little late entering this conversation, but how about this for a
solution?
Don't use String constants that need to be intern()'d in the <clinit> of
Hashtable. Instead, explicitly create all Strings needed during bootstrap
via the String(char[]) constructor. Provided that ObjectStreamField in turn
does not intern() the strings, you are set.
// used for serializing instances of this class. Note: since
String.intern()
// relies on Hashtable during the bootstrap process, we cannot use
string
// literals here.
private static final ObjectStreamField[] serialPersistentFields =
{ new ObjectStreamField(new String(
new char[] {'l','o','a','d','F','a','c','t','o','r'}),
float.class),
new ObjectStreamField(new String(
new char[] {'t','h','r','e','s','h','o','l','d'}), int.class) };
--
Eric Blake, Elixent, Castlemead, Lwr Castle St., Bristol BS1 3AG, UK
address@hidden tel:+44(0)117 917 5611