Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Plain View
Accumulo >> mail # dev >> Bug In Text Class - getLength() and getBytes().length are different.


Copy link to this message
-
Bug In Text Class - getLength() and getBytes().length are different.
The following code (the TextTest class) displays:

cq: [5000000000000000]
cq: [16]
cq: [16]
cq: [5000000000000000]
cq: [16]
cq: [17]

You'll notice that the last two numbers are different, but they should
both be 16. This bug affects Accumulo because of the following code in
Mutation:

  private void put(byte b[]) {
    buffer.writeVLong(b.length);
    buffer.add(b, 0, b.length);
  }

  private void put(Text t) {
    buffer.writeVLong(t.getLength());
    buffer.add(t.getBytes(), 0, t.getLength());
  }

I should be able to call either of the following to get the same
result but I can't.

  put("5000000000000000".getBytes());
  put(new Text("5000000000000000"));

Has anyone else run into this issue? Any workarounds or fixes?

----

package com.codebits.accumulo;

import org.apache.hadoop.io.Text;

public class TextTest {

  public static void main(String[] args) {
    String s = "5000000000000000";
    System.out.println("cq: [" + s + "]");
    System.out.println("cq: [" + s.length() + "]");
    System.out.println("cq: [" + s.getBytes().length + "]");

    Text cq = new Text(s);
    System.out.println("cq: [" + cq + "]");
    System.out.println("cq: [" + cq.getLength() + "]");
    System.out.println("cq: [" + cq.getBytes().length + "]");
  }

}
+
Marc Parisi 2012-11-13, 18:13
+
Keith Turner 2012-11-13, 18:13
+
John Vines 2012-11-13, 18:23
+
David Medinets 2012-11-13, 18:50