From 355857cbebfa68a8f5e47f1e3e21a61c9414d189 Mon Sep 17 00:00:00 2001 From: William Barker Date: Sat, 20 Jun 2009 03:00:18 +0000 Subject: [PATCH] Change Complex to use readResolve instead of introspection git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@786751 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/math/complex/Complex.java | 34 ++++--------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/src/java/org/apache/commons/math/complex/Complex.java b/src/java/org/apache/commons/math/complex/Complex.java index ab4bf7549..1b0f5637d 100644 --- a/src/java/org/apache/commons/math/complex/Complex.java +++ b/src/java/org/apache/commons/math/complex/Complex.java @@ -17,8 +17,6 @@ package org.apache.commons.math.complex; -import java.io.IOException; -import java.io.ObjectInputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -973,33 +971,15 @@ public class Complex implements FieldElement, Serializable { } /** - * Deserialize a Complex Object. - * @param ois The stream to deserialize from. - * @throws IOException If there is an error reading the stream. - * @throws ClassNotFoundException If this class cannot be found. + *

Resolve the transient fields in a deserialized Complex Object.

+ *

Subclasses will need to override {@link #createComplex} to deserialize properly

+ * @return A Complex instance with all fields resolved. + * @since 2.0 */ - private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { - ois.defaultReadObject(); - - try { - final java.lang.reflect.Field fNaN = getClass().getDeclaredField("isNaN"); - fNaN.setAccessible(true); - fNaN.set(this, Double.isNaN(real) || Double.isNaN(imaginary)); - final java.lang.reflect.Field fInf = getClass().getDeclaredField("isInfinite"); - fInf.setAccessible(true); - fInf.set(this, !isNaN && (Double.isInfinite(real) || Double.isInfinite(imaginary))); - } catch (IllegalAccessException iae) { - IOException ioe = new IOException(); - ioe.initCause(iae); - throw ioe; - } catch (NoSuchFieldException nsfe) { - IOException ioe = new IOException(); - ioe.initCause(nsfe); - throw ioe; - } - + private final Object readResolve() { + return createComplex(real, imaginary); } - + /** {@inheritDoc} */ public ComplexField getField() { return ComplexField.getInstance();