Serialization puzzlement (was: Utility for checking API compatibilitywith JDK)

Warren Levy warrenl@cygnus.com
Wed Jul 26 10:36:00 GMT 2000


On 2000年7月26日, Jochen Hoenicke wrote:
> Nonfinal static fields that are initialized and "static {...}" blocks
> in the java code are compiled to a "<clinit>" constructor in bytecode.
> To calculate the serialVersionUID, classpath has to know the presence
> of this constructor. IIRC it uses a native methods for this, so
> check if this works for libgcj.

Bingo! Thanks, this was it; including the <clinit> constructor in the
calculation produces the matching value to the JDK (as obtained from the
serialver utility).
Classpath calls a private static method in ObjectStreamClass
(hasClassInitializer) to check this; which in turn calls a Class method: 
	Class classArgs[] = {};
	Method m = clazz.getMethod ("<clinit>", classArgs);
which is implemented in both libgcj and Classpath as a native method.
Interestingly, a test program using the Classpath ObjectStreamClass built
with the JDK also yielded the same oversight of the <clinit> constructor
for the calculation.
Since the JDK was using it's own Class.getMethod, I suspect that the
proper fix will be in java.io.ObjectStreamClass rather than tweaking
Classpath's & libgcj's java.lang.Class.getMethod.
Thanks again for pointing this out! It was a huge help.
--warrenl


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /