accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmil...@apache.org
Subject [accumulo] branch main updated: Add test and fix for bug in KeyBuilder (#2170)
Date Thu, 17 Jun 2021 13:40:57 GMT
This is an automated email from the ASF dual-hosted git repository.

mmiller pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/main by this push:
     new 1fecdd3  Add test and fix for bug in KeyBuilder (#2170)
1fecdd3 is described below

commit 1fecdd378f2bc15955baa371ac9bb706bcc94dfc
Author: Mike Miller <mmiller@apache.org>
AuthorDate: Thu Jun 17 09:40:49 2021 -0400

    Add test and fix for bug in KeyBuilder (#2170)
    
    * Replace error prone CharsetEncoder with toString() and getBytes()
---
 .../main/java/org/apache/accumulo/core/data/KeyBuilder.java | 13 +------------
 .../java/org/apache/accumulo/core/data/KeyBuilderTest.java  | 10 ++++++++++
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/core/src/main/java/org/apache/accumulo/core/data/KeyBuilder.java b/core/src/main/java/org/apache/accumulo/core/data/KeyBuilder.java
index 100a8cc..1d625b8 100644
--- a/core/src/main/java/org/apache/accumulo/core/data/KeyBuilder.java
+++ b/core/src/main/java/org/apache/accumulo/core/data/KeyBuilder.java
@@ -20,11 +20,6 @@ package org.apache.accumulo.core.data;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
 import org.apache.accumulo.core.security.ColumnVisibility;
 import org.apache.hadoop.io.Text;
 
@@ -326,13 +321,7 @@ public class KeyBuilder {
     }
 
     private byte[] encodeCharSequence(CharSequence chars) {
-      CharsetEncoder encoder = UTF_8.newEncoder().onMalformedInput(CodingErrorAction.REPORT)
-          .onUnmappableCharacter(CodingErrorAction.REPORT);
-      try {
-        return encoder.encode(CharBuffer.wrap(chars)).array();
-      } catch (CharacterCodingException ex) {
-        throw new RuntimeException("KeyBuilder supports only CharSequences encoded in UTF-8",
ex);
-      }
+      return chars.toString().getBytes(UTF_8);
     }
 
     @Override
diff --git a/core/src/test/java/org/apache/accumulo/core/data/KeyBuilderTest.java b/core/src/test/java/org/apache/accumulo/core/data/KeyBuilderTest.java
index 8f795c5..70f02e5 100644
--- a/core/src/test/java/org/apache/accumulo/core/data/KeyBuilderTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/data/KeyBuilderTest.java
@@ -305,4 +305,14 @@ public class KeyBuilderTest {
     keyExpected.setDeleted(false);
     assertEquals(keyExpected, keyBuilt);
   }
+
+  /**
+   * Tests bug where a String of 10 chars or longer was being encoded incorrectly.
+   */
+  @Test
+  public void test10CharactersBug() {
+    Key keyBuilt1 = Key.builder().row(rowText).family("1234567890").build();
+    Key keyBuilt2 = Key.builder().row(rowText).family(new Text("1234567890")).build();
+    assertEquals(keyBuilt1, keyBuilt2);
+  }
 }

Mime
View raw message