< prev index next >

src/java.base/share/classes/java/io/ObjectStreamClass.java

Print this page
*** 32,10 ***
--- 32,11 ---
  import java.lang.ref.ReferenceQueue;
  import java.lang.ref.SoftReference;
  import java.lang.ref.WeakReference;
  import java.lang.reflect.Constructor;
  import java.lang.reflect.Field;
+ import java.lang.reflect.InaccessibleObjectException;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.RecordComponent;
  import java.lang.reflect.UndeclaredThrowableException;
  import java.lang.reflect.Member;
  import java.lang.reflect.Method;

*** 501,10 ***
--- 502,11 ---
      private ObjectStreamClass(final Class<?> cl) {
          this.cl = cl;
          name = cl.getName();
          isProxy = Proxy.isProxyClass(cl);
          isEnum = Enum.class.isAssignableFrom(cl);
+         boolean isPrimitiveClass = cl.isPrimitiveClass();
          isRecord = cl.isRecord();
          serializable = Serializable.class.isAssignableFrom(cl);
          externalizable = Externalizable.class.isAssignableFrom(cl);
  
          Class<?> superCl = cl.getSuperclass();

*** 572,10 ***
--- 574,12 ---
          }
  
          if (deserializeEx == null) {
              if (isEnum) {
                  deserializeEx = new ExceptionInfo(name, "enum type");
+             } else if (isPrimitiveClass && writeReplaceMethod == null) {
+                 deserializeEx = new ExceptionInfo(name, "primitive class");
              } else if (cons == null && !isRecord) {
                  deserializeEx = new ExceptionInfo(name, "no valid constructor");
              }
          }
          if (isRecord && canonicalCtr == null) {

*** 1558,11 ***
          try {
              Constructor<?> cons = cl.getDeclaredConstructor((Class<?>[]) null);
              cons.setAccessible(true);
              return ((cons.getModifiers() & Modifier.PUBLIC) != 0) ?
                  cons : null;
!         } catch (NoSuchMethodException ex) {
              return null;
          }
      }
  
      /**
--- 1562,11 ---
          try {
              Constructor<?> cons = cl.getDeclaredConstructor((Class<?>[]) null);
              cons.setAccessible(true);
              return ((cons.getModifiers() & Modifier.PUBLIC) != 0) ?
                  cons : null;
!         } catch (NoSuchMethodException | InaccessibleObjectException ex) {
              return null;
          }
      }
  
      /**

*** 1887,12 ***
                  String[] ifaceNames = new String[interfaces.length];
                  for (int i = 0; i < interfaces.length; i++) {
                      ifaceNames[i] = interfaces[i].getName();
                  }
                  Arrays.sort(ifaceNames);
                  for (int i = 0; i < ifaceNames.length; i++) {
!                     dout.writeUTF(ifaceNames[i]);
                  }
              }
  
              Field[] fields = cl.getDeclaredFields();
              MemberSignature[] fieldSigs = new MemberSignature[fields.length];
--- 1891,14 ---
                  String[] ifaceNames = new String[interfaces.length];
                  for (int i = 0; i < interfaces.length; i++) {
                      ifaceNames[i] = interfaces[i].getName();
                  }
                  Arrays.sort(ifaceNames);
+                 // Skip IdentityObject to keep the computed SVUID the same.
                  for (int i = 0; i < ifaceNames.length; i++) {
!                     if (!"java.lang.IdentityObject".equals(ifaceNames[i]))
+                         dout.writeUTF(ifaceNames[i]);
                  }
              }
  
              Field[] fields = cl.getDeclaredFields();
              MemberSignature[] fieldSigs = new MemberSignature[fields.length];
< prev index next >