diff options
author | Elliott Hughes <enh@google.com> | 2010-03-25 11:30:13 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2010-03-25 11:30:13 -0700 |
commit | b57e439ac3f5401e39dbe4d9097e476fe20b889e (patch) | |
tree | 8cb2d9d3b90e73661462c7dfe3e7e699eb396bc6 /luni | |
parent | 9e95c528a090dac847aa97fec1b0ad331929c685 (diff) | |
download | libcore-b57e439ac3f5401e39dbe4d9097e476fe20b889e.zip libcore-b57e439ac3f5401e39dbe4d9097e476fe20b889e.tar.gz libcore-b57e439ac3f5401e39dbe4d9097e476fe20b889e.tar.bz2 |
Apply https://issues.apache.org/jira/browse/HARMONY-4307.
They didn't add a test for this; supposedly it fixed a flaky AWT test. But
the change looks plausible.
Change-Id: I358849a20d5e38d01d6c77a4c335002bb7bba095
Diffstat (limited to 'luni')
-rw-r--r-- | luni/src/main/java/java/io/ObjectStreamField.java | 75 |
1 files changed, 47 insertions, 28 deletions
diff --git a/luni/src/main/java/java/io/ObjectStreamField.java b/luni/src/main/java/java/io/ObjectStreamField.java index 3baebf7..ae642df 100644 --- a/luni/src/main/java/java/io/ObjectStreamField.java +++ b/luni/src/main/java/java/io/ObjectStreamField.java @@ -134,6 +134,7 @@ public class ObjectStreamField implements Comparable<Object> { } this.name = name; this.typeString = signature.replace('.', '/').intern(); + defaultResolve(); this.isDeserialized = true; } @@ -348,34 +349,17 @@ public class ObjectStreamField implements Comparable<Object> { } void resolve(ClassLoader loader) { + if (typeString == null && isPrimitive()){ + // primitive type declared in a serializable class + typeString = String.valueOf(getTypeCode()); + } + if (typeString.length() == 1) { - switch (typeString.charAt(0)) { - case 'I': - type = Integer.TYPE; - return; - case 'B': - type = Byte.TYPE; - return; - case 'C': - type = Character.TYPE; - return; - case 'S': - type = Short.TYPE; - return; - case 'Z': - type = Boolean.TYPE; - return; - case 'J': - type = Long.TYPE; - return; - case 'F': - type = Float.TYPE; - return; - case 'D': - type = Double.TYPE; - return; + if (defaultResolve()) { + return; } } + String className = typeString.replace('/', '.'); if (className.charAt(0) == 'L') { // remove L and ; @@ -383,15 +367,14 @@ public class ObjectStreamField implements Comparable<Object> { } try { Class<?> cl = Class.forName(className, false, loader); - type = (cl.getClassLoader() == null) ? cl - : new WeakReference<Class<?>>(cl); + type = (cl.getClassLoader() == null) ? cl : new WeakReference<Class<?>>(cl); } catch (ClassNotFoundException e) { // Ignored } } /** - * Indicats whether this field is unshared. + * Indicates whether this field is unshared. * * @return {@code true} if this field is unshared, {@code false} otherwise. */ @@ -402,4 +385,40 @@ public class ObjectStreamField implements Comparable<Object> { void setUnshared(boolean unshared) { this.unshared = unshared; } + + /** + * Resolves typeString into type. Returns true if the type is primitive + * and false otherwise. + */ + private boolean defaultResolve() { + switch (typeString.charAt(0)) { + case 'I': + type = Integer.TYPE; + return true; + case 'B': + type = Byte.TYPE; + return true; + case 'C': + type = Character.TYPE; + return true; + case 'S': + type = Short.TYPE; + return true; + case 'Z': + type = Boolean.TYPE; + return true; + case 'J': + type = Long.TYPE; + return true; + case 'F': + type = Float.TYPE; + return true; + case 'D': + type = Double.TYPE; + return true; + default: + type = Object.class; + return false; + } + } } |