From 98660bef8667d75a798b67f073703cd9ec051e9c Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Thu, 24 May 2007 21:15:41 +0000 Subject: Fix bug which would throw spurious IllegalArgumentException from StorableGenerator. --- .../com/amazon/carbonado/info/ChainedProperty.java | 41 +++++++++++++++++----- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/info') diff --git a/src/main/java/com/amazon/carbonado/info/ChainedProperty.java b/src/main/java/com/amazon/carbonado/info/ChainedProperty.java index d5b41a8..0299ae8 100644 --- a/src/main/java/com/amazon/carbonado/info/ChainedProperty.java +++ b/src/main/java/com/amazon/carbonado/info/ChainedProperty.java @@ -20,7 +20,6 @@ package com.amazon.carbonado.info; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; @@ -300,18 +299,42 @@ public class ChainedProperty implements Appender { } if (obj instanceof ChainedProperty) { ChainedProperty other = (ChainedProperty) obj; - if (getType() == other.getType() && mPrime.equals(other.mPrime)) { - if (mChain == null) { - return other.mChain == null; - } - if (other.mChain != null) { - return Arrays.equals(mChain, other.mChain); - } - } + // Note: Since StorableProperty instances are not canonicalized, + // they must be compared with the '==' operator instead of the + // equals method. Otherwise, canonical ChainedProperty instances + // may refer to StorableProperty instances which are no longer + // available through the Introspector. + return getType() == other.getType() && mPrime == other.mPrime + && identityEquals(mChain, other.mChain); } return false; } + /** + * Compares objects for equality using '==' operator instead of equals method. + */ + private static boolean identityEquals(Object[] a, Object[] a2) { + if (a == a2) { + return true; + } + if (a == null || a2 == null) { + return false; + } + + int length = a.length; + if (a2.length != length) { + return false; + } + + for (int i=0; i