From a7d8d64aad0a4f47fadd3357a8ce2418691ab073 Mon Sep 17 00:00:00 2001 From: Warren Levy Date: Fri, 6 Oct 2000 00:03:07 +0000 Subject: * Makefile.am: Removed Replaceable.java and Resolvable.java. * ObjectInputStream.java (processResolution): Fixed typo in method name. (processResolution): Handle readResolve method via reflection with removal of Resolvable interface. * ObjectOutputStream.java (writeObject): Handle writeReplace method via reflection with removal of Replaceable interface. * Replaceable.java: Removed. * Resolvable.java: Removed. Serialization mods. Note: The interfaces java.io.Replaceable and java.io.Resolvable were only temporary additions to JDK 1.2 beta versions and were not included in the JDK 1.2 final. The Serialization spec instructs how to deal with their methods (via reflection). --- java/io/ObjectOutputStream.java | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'java/io/ObjectOutputStream.java') diff --git a/java/io/ObjectOutputStream.java b/java/io/ObjectOutputStream.java index 545675952..33caa99c2 100644 --- a/java/io/ObjectOutputStream.java +++ b/java/io/ObjectOutputStream.java @@ -28,6 +28,9 @@ executable file might be covered by the GNU General Public License. */ package java.io; import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; import java.util.Hashtable; import gnu.java.io.ObjectIdentityWrapper; @@ -239,13 +242,33 @@ public class ObjectOutputStream extends OutputStream Object replacedObject = null; - if ((replacementEnabled || obj instanceof Replaceable) + if ((replacementEnabled || obj instanceof Serializable) && ! replaceDone) { replacedObject = obj; - if (obj instanceof Replaceable) - obj = ((Replaceable)obj).writeReplace (); + if (obj instanceof Serializable) + { + Method m = null; + try + { + Class classArgs[] = {}; + m = obj.getClass ().getDeclaredMethod ("writeReplace", + classArgs); + // m can't be null by definition since an exception would + // have been thrown so a check for null is not needed. + obj = m.invoke (obj, new Object[] {}); + } + catch (NoSuchMethodException ignore) + { + } + catch (IllegalAccessException ignore) + { + } + catch (InvocationTargetException ignore) + { + } + } if (replacementEnabled) obj = replaceObject (obj); -- cgit v1.2.1