Browse Source

HADOOP-3274. The default constructor of BytesWritable creates empty byte array. Contributed by Tsz Wo (Nicholas), SZE.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@650332 13f79535-47bb-0310-9956-ffa450edef68
Konstantin Shvachko 17 years ago
parent
commit
a4b60cb543
2 changed files with 6 additions and 4 deletions
  1. 3 0
      CHANGES.txt
  2. 3 4
      src/java/org/apache/hadoop/io/BytesWritable.java

+ 3 - 0
CHANGES.txt

@@ -33,6 +33,9 @@ Trunk (unreleased changes)
 
 
   OPTIMIZATIONS
   OPTIMIZATIONS
 
 
+    HADOOP-3274. The default constructor of BytesWritable creates empty 
+    byte array. (Tsz Wo (Nicholas), SZE via shv)
+
   BUG FIXES
   BUG FIXES
 
 
     HADOOP-2905. 'fsck -move' triggers NPE in NameNode. 
     HADOOP-2905. 'fsck -move' triggers NPE in NameNode. 

+ 3 - 4
src/java/org/apache/hadoop/io/BytesWritable.java

@@ -30,16 +30,15 @@ import java.io.DataOutput;
  */
  */
 public class BytesWritable implements WritableComparable {
 public class BytesWritable implements WritableComparable {
   private static final int LENGTH_BYTES = 4;
   private static final int LENGTH_BYTES = 4;
+  private static final byte[] EMPTY_BYTES = {};
+
   private int size;
   private int size;
   private byte[] bytes;
   private byte[] bytes;
   
   
   /**
   /**
    * Create a zero-size sequence.
    * Create a zero-size sequence.
    */
    */
-  public BytesWritable() {
-    size = 0;
-    bytes = new byte[100];
-  }
+  public BytesWritable() {this(EMPTY_BYTES);}
   
   
   /**
   /**
    * Create a BytesWritable using the byte array as the initial value.
    * Create a BytesWritable using the byte array as the initial value.