< prev index next >
src/java.base/share/classes/java/io/ObjectStreamField.java
Print this page
rev 13139 : 8143926: ObjectStreamField constructor eagerly load ObjectStreamClass
Reviewed-by: chegar, shade, alanb
*** 89,99 ****
throw new NullPointerException();
}
this.name = name;
this.type = type;
this.unshared = unshared;
! signature = ObjectStreamClass.getClassSignature(type).intern();
field = null;
}
/**
* Creates an ObjectStreamField representing a field with the given name,
--- 89,99 ----
throw new NullPointerException();
}
this.name = name;
this.type = type;
this.unshared = unshared;
! signature = getClassSignature(type).intern();
field = null;
}
/**
* Creates an ObjectStreamField representing a field with the given name,
*** 120,129 ****
--- 120,180 ----
case 'L':
case '[': type = Object.class; break;
default: throw new IllegalArgumentException("illegal signature");
}
}
+ /**
+ * Returns JVM type signature for given primitive.
+ */
+ private static String getPrimitiveSignature(Class<?> cl) {
+ if (cl == Integer.TYPE)
+ return "I";
+ else if (cl == Byte.TYPE)
+ return "B";
+ else if (cl == Long.TYPE)
+ return "J";
+ else if (cl == Float.TYPE)
+ return "F";
+ else if (cl == Double.TYPE)
+ return "D";
+ else if (cl == Short.TYPE)
+ return "S";
+ else if (cl == Character.TYPE)
+ return "C";
+ else if (cl == Boolean.TYPE)
+ return "Z";
+ else if (cl == Void.TYPE)
+ return "V";
+ else
+ throw new InternalError();
+ }
+
+ /**
+ * Returns JVM type signature for given class.
+ */
+ /*package-private*/ static String getClassSignature(Class<?> cl) {
+ if (cl.isPrimitive()) {
+ return getPrimitiveSignature(cl);
+ } else {
+ return appendClassSignature(new StringBuilder(), cl).toString();
+ }
+ }
+
+ /*package-private*/ static StringBuilder appendClassSignature(StringBuilder sbuf, Class<?> cl) {
+ while (cl.isArray()) {
+ sbuf.append('[');
+ cl = cl.getComponentType();
+ }
+
+ if (cl.isPrimitive()) {
+ sbuf.append(getPrimitiveSignature(cl));
+ } else {
+ sbuf.append('L').append(cl.getName().replace('.', '/')).append(';');
+ }
+
+ return sbuf;
+ }
/**
* Creates an ObjectStreamField representing the given field with the
* specified unshared setting. For compatibility with the behavior of
* earlier serialization implementations, a "showType" parameter is
*** 135,145 ****
this.field = field;
this.unshared = unshared;
name = field.getName();
Class<?> ftype = field.getType();
type = (showType || ftype.isPrimitive()) ? ftype : Object.class;
! signature = ObjectStreamClass.getClassSignature(ftype).intern();
}
/**
* Get the name of this field.
*
--- 186,196 ----
this.field = field;
this.unshared = unshared;
name = field.getName();
Class<?> ftype = field.getType();
type = (showType || ftype.isPrimitive()) ? ftype : Object.class;
! signature = getClassSignature(ftype).intern();
}
/**
* Get the name of this field.
*
< prev index next >