From 3db26bff365de7d2d4e7fc45ad31b8104c78a0ae Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 25 Mar 2008 05:38:00 +0000 Subject: Fixes for bugs as reported by FindBugs. --- src/main/java/com/amazon/carbonado/filter/BinaryOpFilter.java | 4 ++-- src/main/java/com/amazon/carbonado/filter/FilterValues.java | 2 ++ src/main/java/com/amazon/carbonado/info/ChainedProperty.java | 2 +- src/main/java/com/amazon/carbonado/qe/PropertyFilterList.java | 2 +- src/main/java/com/amazon/carbonado/qe/StorableIndexSet.java | 4 +++- src/main/java/com/amazon/carbonado/raw/DataEncoder.java | 9 ++------- src/main/java/com/amazon/carbonado/raw/KeyEncoder.java | 4 ++-- .../com/amazon/carbonado/repo/indexed/DerivedIndexesTrigger.java | 5 +++++ .../java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java | 8 ++++++-- .../java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java | 2 +- 10 files changed, 25 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/main/java/com/amazon/carbonado/filter/BinaryOpFilter.java b/src/main/java/com/amazon/carbonado/filter/BinaryOpFilter.java index 640c0ae..ffe81e7 100644 --- a/src/main/java/com/amazon/carbonado/filter/BinaryOpFilter.java +++ b/src/main/java/com/amazon/carbonado/filter/BinaryOpFilter.java @@ -69,11 +69,11 @@ public abstract class BinaryOpFilter extends Filter { return accept(new Binder(), null); } - public boolean isBound() { + public synchronized boolean isBound() { return (mState & BOUND) != 0; } - void markBound() { + synchronized void markBound() { mState |= BOUND; } diff --git a/src/main/java/com/amazon/carbonado/filter/FilterValues.java b/src/main/java/com/amazon/carbonado/filter/FilterValues.java index 954d3ac..6e7202c 100644 --- a/src/main/java/com/amazon/carbonado/filter/FilterValues.java +++ b/src/main/java/com/amazon/carbonado/filter/FilterValues.java @@ -36,6 +36,8 @@ import com.amazon.carbonado.util.Appender; * @author Brian S O'Neill */ public class FilterValues implements Serializable, Appender { + private static final long serialVersionUID = 1L; + private static final Object[] NO_VALUES = new Object[0]; static FilterValues diff --git a/src/main/java/com/amazon/carbonado/info/ChainedProperty.java b/src/main/java/com/amazon/carbonado/info/ChainedProperty.java index d30fc8f..65151e8 100644 --- a/src/main/java/com/amazon/carbonado/info/ChainedProperty.java +++ b/src/main/java/com/amazon/carbonado/info/ChainedProperty.java @@ -395,7 +395,7 @@ public class ChainedProperty implements Serializable, Append System.arraycopy(mOuterJoin, 0, newOuterJoin, 0, mOuterJoin.length); } System.arraycopy(property.mOuterJoin, 0, - newOuterJoin, mOuterJoin.length, + newOuterJoin, getChainCount() + 1, property.mOuterJoin.length); } diff --git a/src/main/java/com/amazon/carbonado/qe/PropertyFilterList.java b/src/main/java/com/amazon/carbonado/qe/PropertyFilterList.java index 279430c..c58aacb 100644 --- a/src/main/java/com/amazon/carbonado/qe/PropertyFilterList.java +++ b/src/main/java/com/amazon/carbonado/qe/PropertyFilterList.java @@ -155,7 +155,7 @@ class PropertyFilterList extends AbstractList - implements Comparator> + implements Comparator>, java.io.Serializable { public int compare(PropertyFilter a, PropertyFilter b) { if (a.getOperator() != b.getOperator()) { diff --git a/src/main/java/com/amazon/carbonado/qe/StorableIndexSet.java b/src/main/java/com/amazon/carbonado/qe/StorableIndexSet.java index 976d5a1..7055b21 100644 --- a/src/main/java/com/amazon/carbonado/qe/StorableIndexSet.java +++ b/src/main/java/com/amazon/carbonado/qe/StorableIndexSet.java @@ -472,7 +472,9 @@ public class StorableIndexSet extends TreeSet> { + private static class StorableIndexComparator + implements Comparator>, java.io.Serializable + { public int compare(StorableIndex a, StorableIndex b) { if (a == b) { return 0; diff --git a/src/main/java/com/amazon/carbonado/raw/DataEncoder.java b/src/main/java/com/amazon/carbonado/raw/DataEncoder.java index 1049644..6eebc93 100644 --- a/src/main/java/com/amazon/carbonado/raw/DataEncoder.java +++ b/src/main/java/com/amazon/carbonado/raw/DataEncoder.java @@ -44,11 +44,6 @@ public class DataEncoder { /** Byte to use for not-null, high ordering */ static final byte NOT_NULL_BYTE_LOW = (byte)~NOT_NULL_BYTE_HIGH; - static final byte[] NULL_BYTE_ARRAY_HIGH = {NULL_BYTE_HIGH}; - static final byte[] NULL_BYTE_ARRAY_LOW = {NULL_BYTE_LOW}; - static final byte[] NOT_NULL_BYTE_ARRAY_HIGH = {NOT_NULL_BYTE_HIGH}; - static final byte[] NOT_NULL_BYTE_ARRAY_LOW = {NOT_NULL_BYTE_LOW}; - /** * Encodes the given signed integer into exactly 4 bytes. * @@ -604,12 +599,12 @@ public class DataEncoder { public static byte[] encodeSingleNullable(byte[] value, int prefixPadding, int suffixPadding) { if (prefixPadding <= 0 && suffixPadding <= 0) { if (value == null) { - return NULL_BYTE_ARRAY_HIGH; + return new byte[] {NULL_BYTE_HIGH}; } int length = value.length; if (length == 0) { - return NOT_NULL_BYTE_ARRAY_HIGH; + return new byte[] {NOT_NULL_BYTE_HIGH}; } byte[] dst = new byte[1 + length]; diff --git a/src/main/java/com/amazon/carbonado/raw/KeyEncoder.java b/src/main/java/com/amazon/carbonado/raw/KeyEncoder.java index 44c5af5..5b11586 100644 --- a/src/main/java/com/amazon/carbonado/raw/KeyEncoder.java +++ b/src/main/java/com/amazon/carbonado/raw/KeyEncoder.java @@ -708,12 +708,12 @@ public class KeyEncoder extends DataEncoder { int prefixPadding, int suffixPadding) { if (prefixPadding <= 0 && suffixPadding <= 0) { if (value == null) { - return NULL_BYTE_ARRAY_LOW; + return new byte[] {NULL_BYTE_LOW}; } int length = value.length; if (length == 0) { - return NOT_NULL_BYTE_ARRAY_LOW; + return new byte[] {NOT_NULL_BYTE_LOW}; } byte[] dst = new byte[1 + length]; diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/DerivedIndexesTrigger.java b/src/main/java/com/amazon/carbonado/repo/indexed/DerivedIndexesTrigger.java index 21c7215..9e69935 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/DerivedIndexesTrigger.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/DerivedIndexesTrigger.java @@ -91,6 +91,11 @@ class DerivedIndexesTrigger extends Trig updateValues(storable, state); } + @Override + public int hashCode() { + return mFetcher.hashCode(); + } + @Override public boolean equals(Object obj) { if (this == obj) { diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java index 4bf4e2b..f12a58e 100644 --- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java @@ -553,8 +553,12 @@ abstract class BDBRepository extends AbstractRepository break; } - if (mSuspendUntil != Long.MIN_VALUE) { - if (System.currentTimeMillis() < mSuspendUntil) { + long suspendUntil; + synchronized (this) { + suspendUntil = mSuspendUntil; + } + if (suspendUntil != Long.MIN_VALUE) { + if (System.currentTimeMillis() < suspendUntil) { continue; } } diff --git a/src/main/java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java b/src/main/java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java index b73a9ce..3cfc94f 100644 --- a/src/main/java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java +++ b/src/main/java/com/amazon/carbonado/spi/AbstractRepositoryBuilder.java @@ -62,7 +62,7 @@ public abstract class AbstractRepositoryBuilder implements RepositoryBuilder { public Iterable getTriggerFactories() { synchronized (mTriggerFactories) { - if (mTriggerFactories == null || mTriggerFactories.size() == 0) { + if (mTriggerFactories.size() == 0) { return Collections.emptyList(); } else { return new ArrayList(mTriggerFactories); -- cgit v1.2.3