classpath
[Top][All Lists]
Advanced

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

Re: question about serialization


From: Ingo Prötel
Subject: Re: question about serialization
Date: Tue, 05 Aug 2003 11:23:34 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204

Hi,

would like to propose a modification to Toms fix. It looks to me as if all fields of a deserialized object are accessible as well as the private readObject-Method. Or does the VM reset the Accessible flag?

I think we need to reset the accessible flag after we are done with the field or method:


private void callReadMethod (Object obj, ObjectStreamClass osc) throws IOException
 {
 ...
   boolean saved = setAccessible(m,true);
   m.invoke (obj, args);
   setAccessible(m,saved);
 ...
 }

 /**
  * Sets the accessible flag of theAccessible in a privileged action.
  * @param theAccessible
  * @param isAccessible
  * @return the previous value of theAccessible.isAccessible()
  */
private static boolean setAccessible(final AccessibleObject theAccessible, boolean isAccessible){
     boolean oldValue = theAccessible.isAccessible();
   AccessController.doPrivileged(new PrivilegedAction()
     {
     public Object run()
       {
       theAccessible.setAccessible(true);
       return null;
       }
     });
   return oldValue;
 }

--ingo





reply via email to

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