This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ObjectStreamClass


Hi Per
Op ma 16-12-2002, om 07:49 schreef Per Bothner:
> Adding all those extra fields just for serialization
> destroyed the whole point of my design.
I got it fixed, note that it will not run on gcj 3.2. I know the fix
works because I tested it using gcj-3.3.jar and the sunvm after writing
a serialized file with the current implementation, then running a
readObject with the fixed one (sunvm). 


-- exception:
Exception in thread "main" java.lang.NullPointerException
   at _ZN4java2io17ObjectStreamClass9setFieldsEPNS_4lang5ClassE
(/usr/lib/libgcj.so.3.0.0)
   at _ZN4java2io17ObjectStreamClassC1EPNS_4lang5ClassE
(/usr/lib/libgcj.so.3.0.0)
   at _ZN4java2io17ObjectStreamClass6lookupEPNS_4lang5ClassE
(/usr/lib/libgcj.so.3.0.0)
   at
_ZN4java2io17ObjectStreamClass22getObjectStreamClassesEPNS_4lang5ClassE
(/usr/lib/libgcj.so.3.0.0)
   at _ZN4java2io17ObjectInputStream10readObjectEv
(/usr/lib/libgcj.so.3.0.0)
   at read.main(java.lang.String[]) (Unknown Source)
*** BigInteger.java	2002-12-17 17:20:17.000000000 +0100
--- BigInteger.java.old	2002-12-17 16:30:53.000000000 +0100
***************
*** 3,9 ****
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.io.IOException;
! import java.io.ObjectStreamField;
  /**
   * @author Warren Levy <warrenl@cygnus.com>
   * @date December 20, 1999.
--- 3,9 ----
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.io.IOException;
! 
  /**
   * @author Warren Levy <warrenl@cygnus.com>
   * @date December 20, 1999.
***************
*** 28,48 ****
     * of this BigInteger, stored in little-endian order, 2's-complement form. */
    transient private int ival;
    transient private int[] words;
!   
!   /** Serialialization version for backwards compatibility
!    */
    private static final long serialVersionUID = -8287574255936472291L;
-   /** Serialization data field
-    */
-   private static final ObjectStreamField serialPersistentFields[] = 
-   {
-     new ObjectStreamField("bitCount",Integer.TYPE),
-     new ObjectStreamField("bitLength",Integer.TYPE),
-     new ObjectStreamField("firstNonzeroByteNum",Integer.TYPE),
-     new ObjectStreamField("lowestSetBit",Integer.TYPE),
-     new ObjectStreamField("signum",Integer.TYPE),
-     new ObjectStreamField("magnitude",byte[].class),
-   };
  
  
    /** We pre-allocate integers in the range minFixNum..maxFixNum. */
--- 28,42 ----
     * of this BigInteger, stored in little-endian order, 2's-complement form. */
    transient private int ival;
    transient private int[] words;
! 
!   // Serialization fields.
!   private int bitCount = -1;
!   private int bitLength = -1;
!   private int firstNonzeroByteNum = -2;
!   private int lowestSetBit = -2;
!   private byte[] magnitude;
!   private int signum;
    private static final long serialVersionUID = -8287574255936472291L;
  
  
    /** We pre-allocate integers in the range minFixNum..maxFixNum. */
***************
*** 2214,2245 ****
      return isNegative() ? x_len * 32 - i : i;
    }
  
!   /** Deserialize fields using serializable fields api, hopefully
!    * prevents crappy code and serialization incompatibilities.
!    * @arg in InputStream delegated to private method thru serialization mechs.
!    **/
!   private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException {
!     ObjectInputStream.GetField fields = in.readFields();
!     fields.get("bitCount",-1);
!     fields.get("bitLength",-1);
!     fields.get("firstNonzeroByteNum",-2);
!     fields.get("lowestSetBit",-2);
!     words = byteArrayToIntArray((byte[])fields.get("magnitude",null),fields.get("signum",-1)<0? -1:0);
      BigInteger result = make(words, words.length);
!     ival = result.ival;
!     words = result.words;
    }
!   /** Serialize using the serializable fields api.
!    * @arg out OutputStream delegated to private method thru serialization mechs.
!    */
!   private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
!     ObjectOutputStream.PutField fields = out.putFields();
!     fields.put("bitCount",-1);
!     fields.put("bitLength",-1);
!     fields.put("firstNonzeroByteNum",-2);
!     fields.put("lowestSetBit",-2);
!     fields.put("signum",signum());
!     fields.put("magnitude", toByteArray());
!     out.writeFields();
    }
  }
--- 2208,2229 ----
      return isNegative() ? x_len * 32 - i : i;
    }
  
!   private void readObject(ObjectInputStream s)
!     throws IOException, ClassNotFoundException
!   {
!     s.defaultReadObject();
!     words = byteArrayToIntArray(magnitude, signum < 0 ? -1 : 0);
      BigInteger result = make(words, words.length);
!     this.ival = result.ival;
!     this.words = result.words;
    }
! 
!   private void writeObject(ObjectOutputStream s)
!     throws IOException, ClassNotFoundException
!   {
!     signum = signum();
!     magnitude = toByteArray();
!     System.out.println(magnitude);
!     s.defaultWriteObject();
    }
  }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]