[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

String/Hashtable bootstrapping problem

From: Patrick Doyle
Subject: String/Hashtable bootstrapping problem
Date: Wed, 4 Jul 2001 12:24:50 -0400 (EDT)

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 makes use of String.internTable, which is a Hashtable,
  and which is initialized in String.<clinit>.

The result is that the first time my VM encounters any string constant,
this sequence of events occurs:

1. String is loaded.
2. String.<clinit> is called, which tries to construct internTable.
3. internTable is a Hashtable, so Hashtable is loaded.
4. Hashtable.<clinit> accesses a string constant.
5. String.<clinit> would be called here, except String is already being
   constructed, so this step is skipped (as per JVM spec 2.17.5)
6. String.<init> to construct the new string.
7. String.intern is called to get the "interned" value for the string.
8. Since internTable is not yet constructed, I get a NullPointerException.

Does anyone have any recommendations as to how I should handle this?
Perhaps I should not call String.intern if String.internTable is null,
relying on the libraries not to try to use two copies of the same constant

Patrick Doyle

reply via email to

[Prev in Thread] Current Thread [Next in Thread]