classpath
[Top][All Lists]
Advanced

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

Re: Object serialization and final fields


From: Mark Wielaard
Subject: Re: Object serialization and final fields
Date: Sun, 28 Mar 2004 17:54:59 +0200

Hi,

On Thu, 2004-03-25 at 21:19, Guilhem Lavaux wrote: 
> Some people has reported failures in kaffe with applications trying to 
> deserialize objects containing final fields. Apparently it is authorized 
>   in the serialization spec but we cannot rely on 
> java.lang.reflect.Field to set them. So our only solution is to bypass 
> the protection in java.lang.reflect.Field by creating new native calls 
> in ObjectStreamField.
> 
> I am proposing the following changes for ObjectStreamField.

It is a bit sad that serialization needs a couple of things that clearly
should have been standard reflection methods/options. Sigh.

I like the idea in general.
Couple of comments/questions.

- ChangeLog entry is missing...

> Index: java/io/ObjectStreamField.java
> ===================================================================
> RCS file: /cvsroot/classpath/classpath/java/io/ObjectStreamField.java,v
> retrieving revision 1.14
> diff -u -b -B -r1.14 ObjectStreamField.java
> -- java/io/ObjectStreamField.java     26 Feb 2004 07:53:15 -0000      1.14
> +++ java/io/ObjectStreamField.java    25 Mar 2004 20:19:43 -0000
> @@ -38,9 +38,10 @@
>  
>  package java.io;
>  
> +import gnu.java.lang.reflect.TypeSignature;
> +
>  import java.lang.reflect.Field;
>  import java.lang.reflect.Modifier;
> -import gnu.java.lang.reflect.TypeSignature;
>  import java.security.AccessController;
>  import java.security.PrivilegedAction;
>  
> @@ -64,7 +65,7 @@
>    {
>      this (field.getName(), field.getType());
>      this.field = field;
> -    toset = !Modifier.isFinal(field.getModifiers());
> +    //toset = !Modifier.isFinal(field.getModifiers());
>    }

Either remove this or make it a real comment explaining why we don't
test this anymore.

>    /**
> @@ -353,11 +354,14 @@
>      return "ObjectStreamField< " + type + " " + name + " >";
>    }
>  
> +  final private native void setBooleanNative(Object obj, boolean val) 
> +    throws IllegalAccessException;
> +

This and the other setXXXNative methods should be moved to
VMObjectStreamClass. You should also provide sample JNI implementations
for this in native/jni/java-io/java_io_VMObjectStreamClass.c
(Note that VmSystem.c has examples for this. See VMSystem
setIn/Out/Err())

Maybe make them static and also provide the field object?

>    final void setBooleanField(Object obj, boolean val)
>    {
>      try
>        {
> -     field.setBoolean(obj, val);
> +     setBooleanNative(obj, val);
>        }
>      catch(IllegalAccessException x)
>        {

Do we want to use the new method unconditionally or only when the field
is final?

Cheers,

Mark

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

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