You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2014/12/05 21:24:43 UTC

svn commit: r1643417 - in /lucene/dev/branches/lucene_solr_4_10/lucene: ./ core/src/java/org/apache/lucene/analysis/tokenattributes/ core/src/java/org/apache/lucene/util/ core/src/test/org/apache/lucene/util/

Author: mikemccand
Date: Fri Dec  5 20:24:43 2014
New Revision: 1643417

URL: http://svn.apache.org/r1643417
Log:
LUCENE-6055: PayloadAttribute.clone() should deep clone its BytesRef

Modified:
    lucene/dev/branches/lucene_solr_4_10/lucene/CHANGES.txt
    lucene/dev/branches/lucene_solr_4_10/lucene/MIGRATE.txt
    lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/analysis/tokenattributes/CharTermAttributeImpl.java
    lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/analysis/tokenattributes/PayloadAttributeImpl.java
    lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/util/AttributeImpl.java
    lucene/dev/branches/lucene_solr_4_10/lucene/core/src/test/org/apache/lucene/util/TestAttributeSource.java

Modified: lucene/dev/branches/lucene_solr_4_10/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/CHANGES.txt?rev=1643417&r1=1643416&r2=1643417&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/CHANGES.txt Fri Dec  5 20:24:43 2014
@@ -39,6 +39,9 @@ Bug fixes
 * LUCENE-5948: RateLimiter now fully inits itself on init.  (Varun
   Thacker via Mike McCandless)
 
+* LUCENE-6055: PayloadAttribute.clone() now does a deep clone of the underlying
+  bytes. (Shai Erera)
+  
 Documentation
 
 * LUCENE-6057: Improve Sort(SortField) docs (Martin Braun via Mike McCandless)

Modified: lucene/dev/branches/lucene_solr_4_10/lucene/MIGRATE.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/MIGRATE.txt?rev=1643417&r1=1643416&r2=1643417&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/MIGRATE.txt (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/MIGRATE.txt Fri Dec  5 20:24:43 2014
@@ -639,3 +639,15 @@ together by Lucene.
   PayloadAttribute's name is unchanged, it just uses the BytesRef
   class to refer to the payload bytes/start offset/end offset 
   (or null if there is no payload).
+
+Bugs fixed in several ValueSource functions may result in different behavior in 
+situations where some documents do not have values for fields wrapped in other 
+ValueSources.  Users who want to preserve the previous behavior may need to wrap 
+their ValueSources in a "DefFunction" along with a ConstValueSource of "0.0".
+
+## PayloadAttributeImpl.clone() (LUCENE-6055)
+
+PayloadAttributeImpl.clone() did a shallow clone which was incorrect, and was
+fixed to do a deep clone. If you require shallow cloning of the underlying bytes,
+you should override PayloadAttributeImpl.clone() to do a shallow clone instead.
+

Modified: lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/analysis/tokenattributes/CharTermAttributeImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/analysis/tokenattributes/CharTermAttributeImpl.java?rev=1643417&r1=1643416&r2=1643417&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/analysis/tokenattributes/CharTermAttributeImpl.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/analysis/tokenattributes/CharTermAttributeImpl.java Fri Dec  5 20:24:43 2014
@@ -88,7 +88,6 @@ public class CharTermAttributeImpl exten
   @Override
   public void fillBytesRef() {
     bytes.copyChars(termBuffer, 0, termLength);
-    bytes.get();
   }
 
   @Override

Modified: lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/analysis/tokenattributes/PayloadAttributeImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/analysis/tokenattributes/PayloadAttributeImpl.java?rev=1643417&r1=1643416&r2=1643417&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/analysis/tokenattributes/PayloadAttributeImpl.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/analysis/tokenattributes/PayloadAttributeImpl.java Fri Dec  5 20:24:43 2014
@@ -55,7 +55,7 @@ public class PayloadAttributeImpl extend
   public PayloadAttributeImpl clone()  {
     PayloadAttributeImpl clone = (PayloadAttributeImpl) super.clone();
     if (payload != null) {
-      clone.payload = payload.clone();
+      clone.payload = BytesRef.deepCopyOf(payload);
     }
     return clone;
   }
@@ -86,7 +86,7 @@ public class PayloadAttributeImpl extend
   @Override
   public void copyTo(AttributeImpl target) {
     PayloadAttribute t = (PayloadAttribute) target;
-    t.setPayload((payload == null) ? null : payload.clone());
+    t.setPayload((payload == null) ? null : BytesRef.deepCopyOf(payload));
   }  
 
   

Modified: lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/util/AttributeImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/util/AttributeImpl.java?rev=1643417&r1=1643416&r2=1643417&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/util/AttributeImpl.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/core/src/java/org/apache/lucene/util/AttributeImpl.java Fri Dec  5 20:24:43 2014
@@ -116,10 +116,10 @@ public abstract class AttributeImpl impl
    * Attributes this implementation supports.
    */
   public abstract void copyTo(AttributeImpl target);
-    
+
   /**
-   * Shallow clone. Subclasses must override this if they 
-   * need to clone any members deeply,
+   * In most cases the clone is, and should be, deep in order to be able to
+   * properly capture the state of all attributes.
    */
   @Override
   public AttributeImpl clone() {

Modified: lucene/dev/branches/lucene_solr_4_10/lucene/core/src/test/org/apache/lucene/util/TestAttributeSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_10/lucene/core/src/test/org/apache/lucene/util/TestAttributeSource.java?rev=1643417&r1=1643416&r2=1643417&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_10/lucene/core/src/test/org/apache/lucene/util/TestAttributeSource.java (original)
+++ lucene/dev/branches/lucene_solr_4_10/lucene/core/src/test/org/apache/lucene/util/TestAttributeSource.java Fri Dec  5 20:24:43 2014
@@ -159,4 +159,21 @@ public class TestAttributeSource extends
     assertTrue("The hashCode is identical, so the captured state was preserved.", hash1 != src1.hashCode());
     assertEquals(src2.hashCode(), src1.hashCode());
   }
+  
+  public void testClonePayloadAttribute() throws Exception {
+    // LUCENE-6055: verify that PayloadAttribute.clone() does deep cloning.
+    PayloadAttributeImpl src = new PayloadAttributeImpl(new BytesRef(new byte[] { 1, 2, 3 }));
+    
+    // test clone()
+    PayloadAttributeImpl clone = src.clone();
+    clone.getPayload().bytes[0] = 10; // modify one byte, srcBytes shouldn't change
+    assertEquals("clone() wasn't deep", 1, src.getPayload().bytes[0]);
+    
+    // test copyTo()
+    clone = new PayloadAttributeImpl();
+    src.copyTo(clone);
+    clone.getPayload().bytes[0] = 10; // modify one byte, srcBytes shouldn't change
+    assertEquals("clone() wasn't deep", 1, src.getPayload().bytes[0]);
+  }
+  
 }