Apache Solr open-source search software
Added javadocs to *Ref about clone() performing a shallow copy. I know, this is obvious and to be expected, but I fell a victim to this anyway, it's a damn thing to debug if you use clone() in hash maps etc. so perhaps it'll help somebody.
Dawid Weiss23cd6d85a38d
diff --git a/lucene/core/src/java/org/apache/lucene/util/BytesRef.java b/lucene/core/src/java/org/apache/lucene/util/BytesRef.javaindex a3eddabf4ef..97310d86171 100644--- a/lucene/core/src/java/org/apache/lucene/util/BytesRef.java+++ b/lucene/core/src/java/org/apache/lucene/util/BytesRef.java@@ -119,11 +119,17 @@ public final class BytesRef implements Comparable<BytesRef>,Cloneable {}}+ /**+ * Returns a shallow clone of this instance (the underlying bytes are+ * <b>not</b> copied and will be shared by both the returned object and this+ * object.+ *+ * @see #deepCopyOf+ */@Overridepublic BytesRef clone() {return new BytesRef(bytes, offset, length);}-/** Calculates the hash code as required by TermsHash during indexing.* <p>It is defined as:diff --git a/lucene/core/src/java/org/apache/lucene/util/CharsRef.java b/lucene/core/src/java/org/apache/lucene/util/CharsRef.javaindex a57e73e0045..4eb6646a53e 100644--- a/lucene/core/src/java/org/apache/lucene/util/CharsRef.java+++ b/lucene/core/src/java/org/apache/lucene/util/CharsRef.java@@ -71,6 +71,13 @@ public final class CharsRef implements Comparable<CharsRef>, CharSequence, Clonethis.length = chars.length;}+ /**+ * Returns a shallow clone of this instance (the underlying characters are+ * <b>not</b> copied and will be shared by both the returned object and this+ * object.+ *+ * @see #deepCopyOf+ */@Overridepublic CharsRef clone() {return new CharsRef(chars, offset, length);diff --git a/lucene/core/src/java/org/apache/lucene/util/IntsRef.java b/lucene/core/src/java/org/apache/lucene/util/IntsRef.javaindex 5ea2aef1c24..f69e10521cd 100644--- a/lucene/core/src/java/org/apache/lucene/util/IntsRef.java+++ b/lucene/core/src/java/org/apache/lucene/util/IntsRef.java@@ -56,6 +56,13 @@ public final class IntsRef implements Comparable<IntsRef>, Cloneable {assert isValid();}+ /**+ * Returns a shallow clone of this instance (the underlying ints are+ * <b>not</b> copied and will be shared by both the returned object and this+ * object.+ *+ * @see #deepCopyOf+ */@Overridepublic IntsRef clone() {return new IntsRef(ints, offset, length);diff --git a/lucene/core/src/java/org/apache/lucene/util/LongsRef.java b/lucene/core/src/java/org/apache/lucene/util/LongsRef.javaindex 62f15b0eb6c..52ad1f106b5 100644--- a/lucene/core/src/java/org/apache/lucene/util/LongsRef.java+++ b/lucene/core/src/java/org/apache/lucene/util/LongsRef.java@@ -55,6 +55,13 @@ public final class LongsRef implements Comparable<LongsRef>, Cloneable {assert isValid();}+ /**+ * Returns a shallow clone of this instance (the underlying longs are+ * <b>not</b> copied and will be shared by both the returned object and this+ * object.+ *+ * @see #deepCopyOf+ */@Overridepublic LongsRef clone() {return new LongsRef(longs, offset, length);