Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Threaded 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 + "]");
  }

}
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB