dlmarion commented on code in PR #5702:
URL: https://github.com/apache/accumulo/pull/5702#discussion_r2180398086


##########
core/src/main/java/org/apache/accumulo/core/data/Mutation.java:
##########
@@ -701,6 +701,40 @@ public void put(byte[] columnFamily, byte[] 
columnQualifier, ColumnVisibility co
         value);
   }
 
+  /**
+   * Puts a modification in this mutation given the values contained in the 
key and the value. All
+   * appropriate fields of the key are defensively copied.
+   *
+   * @param key key containing all key fields
+   * @param value value
+   */
+  public void put(Key key, Value value) {
+    if (!(Arrays.equals(this.getRow(), key.getRow().getBytes()))) {
+      throw new IllegalArgumentException("key row is not equal to mutation 
row");
+    }
+
+    if (key.isDeleted()) {
+      throw new IllegalArgumentException("key must not be marked for 
deletion");
+    }

Review Comment:
   I'm not sure we need this check. What if a user is iterating of deleted keys 
and want's to re-insert them?



##########
core/src/test/java/org/apache/accumulo/core/data/MutationTest.java:
##########
@@ -948,4 +958,139 @@ public void testPrettyPrint() {
 
     assertEquals(expected, m.prettyPrint());
   }
+
+  /**
+   * Test that a null Key passed though {@link Mutation#put(Key, Value)} will 
throw a Null Pointer
+   * Exception.
+   */
+  @Test
+  public void testPutWithNullKey() {
+    Mutation m = new Mutation(new Text("r1"));
+    Key k = null;
+    Value v = nv("v1");
+
+    Throwable exception =
+        assertThrows(NullPointerException.class, () -> m.put(k, v), "Expected 
an NPE");
+
+    assertEquals(
+        "Cannot invoke \"org.apache.accumulo.core.data.Key.getRow()\" because 
\"key\" is null",
+        exception.getMessage());

Review Comment:
   We should probably validate that the Key and Value are non-null using 
`Objects.requireNonNull` in the put(k,v) and putDelete(k,v) methods instead of 
expecting a NPE. 



##########
core/src/main/java/org/apache/accumulo/core/data/Mutation.java:
##########
@@ -701,6 +701,40 @@ public void put(byte[] columnFamily, byte[] 
columnQualifier, ColumnVisibility co
         value);
   }
 
+  /**
+   * Puts a modification in this mutation given the values contained in the 
key and the value. All
+   * appropriate fields of the key are defensively copied.
+   *
+   * @param key key containing all key fields
+   * @param value value
+   */
+  public void put(Key key, Value value) {
+    if (!(Arrays.equals(this.getRow(), key.getRow().getBytes()))) {
+      throw new IllegalArgumentException("key row is not equal to mutation 
row");
+    }

Review Comment:
   May want to use `Key.compareTo(Key, PartialKey.ROW)` here. We are using some 
Hadoop optimized code taken from Guava under the hood.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to