[kaffe] java.io.ObjectInputStream: final field cannot be restored
Guilhem Lavaux
guilhem.lavaux@free.fr
Wed Mar 24 04:11:01 2004
Guilhem Lavaux wrote:
> Guilhem Lavaux wrote:
>
>> Ito Kazumitsu wrote:
>>
>>> Hi,
>>
>>
>>
>> Hi Ito !
>>
>>>
>>> Interested in Prevayler (http://www.prevayler.org/), which is
>>> marked untested in our "Compatibility - Application Testing",
>>> I tried it.
>>>
>>> The result was unsatisfactory. The simplest demo of Prevayler
>>> cannot run on kaffe. After studying the cause of the error,
>>> I found something buggy in java.io.ObjectInputStream.
>>>
>>> My test program is attaced below. The test shows that a
>>> field that is marked "final" cannot be restored by
>>> java.io.ObjectInputStream#readObject.
>>>
>>
>> This is linked to ObjectStreamField.java:67
>>
>> toset = !Modifier.isFinal(field.getModifiers());
>>
>> I guess it was placed there for a good reason but I don't remember
>> which one. We have to check in the spec again.
>>
>
> The reason was quite evident... you can't set a final variable. It's
> rather someone sets (or doesn't set) A to the right value when it is
> initializing a new instance using readObject().
>
> Cheers,
>
> Guilhem.
Actually, the case is getting worse. I have made some more tests and it
depends on the compiler you used to build the class files.
KJC or GCJ-3.3.1, executed by sun's VM: s1 is set by ObjectInputStream
Jikes or Sun's javac, executed by sun's VM: s1 is not set by
ObjectInputStream, the final value is kept.
Also it seems ObjectInputStream is capable of setting final values. That
is a bit annoying as java.lang.reflect.Field's spec says we absolutely
cannot.
So there are two problems in one !
I'll give GCJ-CVS a try later and I will have to fix KJC bytecode
generation also after all.
Cheers,
Guilhem.