Skip to content

Commit

Permalink
8295370: Update java.io.ObjectStreamField to use Class.descriptorString
Browse files Browse the repository at this point in the history
Reviewed-by: bpb, mchung
  • Loading branch information
Roger Riggs committed Oct 14, 2022
1 parent 8487c56 commit 2087424
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 59 deletions.
7 changes: 3 additions & 4 deletions src/java.base/share/classes/java/io/ObjectStreamClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import jdk.internal.access.SharedSecrets;
import jdk.internal.access.JavaSecurityAccess;
import sun.reflect.misc.ReflectUtil;
import static java.io.ObjectStreamField.*;

/**
* Serialization's descriptor for classes. It contains the name and
Expand Down Expand Up @@ -1564,10 +1563,10 @@ private static String getMethodSignature(Class<?>[] paramTypes,
StringBuilder sb = new StringBuilder();
sb.append('(');
for (int i = 0; i < paramTypes.length; i++) {
appendClassSignature(sb, paramTypes[i]);
sb.append(paramTypes[i].descriptorString());
}
sb.append(')');
appendClassSignature(sb, retType);
sb.append(retType.descriptorString());
return sb.toString();
}

Expand Down Expand Up @@ -1881,7 +1880,7 @@ private static class MemberSignature {
public MemberSignature(Field field) {
member = field;
name = field.getName();
signature = getClassSignature(field.getType());
signature = field.getType().descriptorString();
}

public MemberSignature(Constructor<?> cons) {
Expand Down
58 changes: 3 additions & 55 deletions src/java.base/share/classes/java/io/ObjectStreamField.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -124,58 +124,6 @@ public ObjectStreamField(String name, Class<?> type, boolean unshared) {
};
}

/**
* 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.
*/
static String getClassSignature(Class<?> cl) {
if (cl.isPrimitive()) {
return getPrimitiveSignature(cl);
} else {
return appendClassSignature(new StringBuilder(), cl).toString();
}
}

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
Expand All @@ -190,7 +138,7 @@ static StringBuilder appendClassSignature(StringBuilder sbuf, Class<?> cl) {
name = field.getName();
Class<?> ftype = field.getType();
type = (showType || ftype.isPrimitive()) ? ftype : Object.class;
signature = getClassSignature(ftype).intern();
signature = ftype.descriptorString().intern();
}

/**
Expand Down Expand Up @@ -347,7 +295,7 @@ String getSignature() {
// of the public constructors are used, in which case type is always
// initialized to the exact type we want the signature to represent.
if (sig == null) {
typeSignature = sig = getClassSignature(type).intern();
typeSignature = sig = type.descriptorString().intern();
}
return sig;
}
Expand Down

1 comment on commit 2087424

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.