[BUG] cicular dependencies between Toolkit & Defaults during class initialization.
Peter C. Mehlitz
peter at transvirtual.com
Fri Aug 7 02:21:58 PDT 1998
Pascal,
On Thu, 06 Aug 1998, Pascal Bourguignon wrote:
>(What I don't understand is why Defaults class is not initialized even
>before starting the initialization of the Toolkit class since there is this
>dependency, is it a bug/feature of Java, or is it a bug of the compiler, or
>is it a bug of the virtual machine?)
You can't initialize Defaults completely since it uses Color and Font objects
(which, in turn, reference Toolkit). Of course, you could reduce these
references to Strings and ints, but this would put the burden of generating
(and storing) the real objects to all of the Defaults clients (and there are
lots of them).
The main problem with Toolkit / Defaults / Color / Font .. initialization is
that you can come in from all of these classes, there is no real "starting
point".
The problem you mentioned is caused by the native initialization of the static
Color fields (i.e. during the first step of Color class init).
Since Java allows for cyclic/recursive static initialization, the trick is to
split Defaults / Color initialization into sections which can be "serialized"
(the Defaults init just refers to Java-initialized Color objects). In the Color
case, we have done this already by doing the native init of static Color fields
from the Color "static {..}" block, the Java init is done as before (i.e. there
is a private Color ctor that does just the Java init). Not ideal, but working..
Fonts are not such a big issue because it does not have relevant static fields
(going native).
Anyway, it's a tradeoff in Defaults - using the "real" classes/objects vs.
getting a "clean" init sequence. You always have o consider this if it comes to
adding new Defaults fields (not being of builtin or java.lang type).
--
Peter Mehlitz Tel: +1 510 704 1660
Transvirtual Technologies, Inc., Fax: +1 510 704 1893
http://www.transvirtual.com Email: peter at transvirtual.com
More information about the kaffe
mailing list