On 27 Jun 2000, Brian Jones wrote:

> Brian Jones <[EMAIL PROTECTED]> writes:
> 
> > Okay, so this got me quite a bit farther... haha... it appears there
> > is something wrong with the implementation of
> > java.io.ObjectStreamClass...
> 
> What's very confusing here is libgcj's implementation has a classpath
> header but does not appear to be exactly the same... so I guess these
> aren't merged yet.  Is anyone working on that?

Hmm, I did a tiny bit of the work on that seems to be different here.
I added the code in libgcj to enforce that the classpath SHA found in
gnu.java.security.provider would be used; I didn't add that to classpath
figuring that that was already handled.  If that was a bad assumption,
I'll just fold in the code.  Basically this (plus a couple imports):

@@ -415,11 +418,24 @@ public class ObjectStreamClass implement
     // cl didn't define serialVersionUID, so we have to compute it
     try
     {
-      MessageDigest md = MessageDigest.getInstance ("SHA");
-      DigestOutputStream digest_out =
-       new DigestOutputStream (nullOutputStream, md);
-      DataOutputStream data_out = new DataOutputStream (digest_out);
+      MessageDigest md = null;
+      DigestOutputStream digest_out = null;
+      DataOutputStream data_out = null;
+
+      try 
+       {
+         md = MessageDigest.getInstance ("SHA");
+       }
+      catch (NoSuchAlgorithmException e)
+       {
+         // If a provider already provides SHA, use it; otherwise, use this.
+         Gnu gnuProvider = new Gnu();
+         Security.addProvider(gnuProvider);
+         md = MessageDigest.getInstance ("SHA");
+       }
 
+      digest_out = new DigestOutputStream (nullOutputStream, md);
+      data_out = new DataOutputStream (digest_out);
       data_out.writeUTF (cl.getName ());
 
       int modifiers = cl.getModifiers ();


The rest of the differences are things done by Andrew Haley
<[EMAIL PROTECTED]> if I'm not mistaken.  It looks like it just does things
in Java that were done in native code in classpath.  That's easy enough to
fold in too if folks desire it.  Here are the mods in case anyone wants to
pass judgment on them:

@@ -530,18 +546,72 @@ public class ObjectStreamClass implement
 
   // Returns the value of CLAZZ's final static long field named
   // `serialVersionUID'.
-  private native long getDefinedSUID (Class clazz);
+  private long getDefinedSUID (Class clazz)
+  {
+    long l = 0;
+    try
+      {
+       // Use getDeclaredField rather than getField, since
serialVersionUID
+       // may not be public AND we only want the serialVersionUID of this
+       // class, not a superclass or interface.
+       Field f = clazz.getDeclaredField ("serialVersionUID");
+       l = f.getLong (null);
+      }
+    catch (java.lang.NoSuchFieldException e)
+      {
+      }
+
+    catch (java.lang.IllegalAccessException e)
+      {
+      }
+
+    return l;
+  }
 
   // Returns the value of CLAZZ's private static final field named
   // `serialPersistantFields'.
-  private native ObjectStreamField[] getSerialPersistantFields (Class
clazz);
+  private ObjectStreamField[] getSerialPersistantFields (Class clazz)
+  {
+    ObjectStreamField[] o = null;
+    try
+      {
+       // Use getDeclaredField rather than getField for the same reason
+       // as above in getDefinedSUID.
+       Field f = clazz.getDeclaredField ("getSerialPersistantFields");
+       o = (ObjectStreamField[])f.get (null);
+      }
+    catch (java.lang.NoSuchFieldException e)
+      {
+      }
+    catch (java.lang.IllegalAccessException e)
+      {
+      }
+
+    return o;
+  }
+
 
   // Returns true if CLAZZ has a static class initializer
   // (a.k.a. <clinit>).
   //
   // A NoSuchMethodError is raised if CLAZZ has no such method.
-  private static native boolean hasClassInitializer (Class clazz);
+  private static boolean hasClassInitializer (Class clazz)
+    throws java.lang.NoSuchMethodError
+  {
+    Method m = null;
 
+    try
+      {
+       Class classArgs[] = {};
+       m = clazz.getMethod ("<clinit>", classArgs);
+      }
+    catch (java.lang.NoSuchMethodException e)
+      {
+       throw new java.lang.NoSuchMethodError ();
+      }
+
+    return m != null;
+  }
 
   public static final ObjectStreamField[] NO_FIELDS = {};
 


If folks want this in classpath, let me know and I'll merge these in.
--warrenl

Reply via email to