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. --- .../amazon/carbonado/gen/StorableGenerator.java | 9 ++--- .../com/amazon/carbonado/info/ChainedProperty.java | 41 +++++++++++++++++----- 2 files changed, 37 insertions(+), 13 deletions(-) (limited to 'src/main/java/com/amazon/carbonado') diff --git a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java index 0fa8708..5f473cb 100644 --- a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java +++ b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java @@ -1885,7 +1885,7 @@ public final class StorableGenerator { addAltKeyMethods: for (int i=0; i> altProps = - new HashMap>(); + new LinkedHashMap>(); StorableKey altKey = mInfo.getAlternateKey(i); @@ -1905,7 +1905,7 @@ public final class StorableGenerator { // Define protected isRequiredDataInitialized method. defineIsRequiredDataInitialized: { Map> requiredProperties = - new HashMap>(); + new LinkedHashMap>(); for (StorableProperty property : mAllProperties.values()) { if (!property.isDerived() && @@ -2686,7 +2686,7 @@ public final class StorableGenerator { b.returnValue(TypeDesc.BOOLEAN); } - private int findPropertyOrdinal(StorableProperty property) { + private int findPropertyOrdinal(StorableProperty property) { int ordinal = 0; for (StorableProperty p : mAllProperties.values()) { if (p == property) { @@ -2694,7 +2694,8 @@ public final class StorableGenerator { } ordinal++; } - throw new IllegalArgumentException(); + throw new IllegalArgumentException + ("Unable to find property " + property + " in " + mAllProperties); } /** 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