Return-Path: X-Original-To: apmail-accumulo-dev-archive@www.apache.org Delivered-To: apmail-accumulo-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 54A5BD317 for ; Tue, 13 Nov 2012 18:51:06 +0000 (UTC) Received: (qmail 51785 invoked by uid 500); 13 Nov 2012 18:51:06 -0000 Delivered-To: apmail-accumulo-dev-archive@accumulo.apache.org Received: (qmail 51747 invoked by uid 500); 13 Nov 2012 18:51:06 -0000 Mailing-List: contact dev-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list dev@accumulo.apache.org Received: (qmail 51739 invoked by uid 99); 13 Nov 2012 18:51:06 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Nov 2012 18:51:06 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of david.medinets@gmail.com designates 209.85.220.169 as permitted sender) Received: from [209.85.220.169] (HELO mail-vc0-f169.google.com) (209.85.220.169) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Nov 2012 18:50:58 +0000 Received: by mail-vc0-f169.google.com with SMTP id fl17so9158177vcb.0 for ; Tue, 13 Nov 2012 10:50:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=iZ6vbi1vxsuJpPBSjImUq683VbzhFMGASOuA5RMzctI=; b=bT8UYrrT76xhkje6Cwf6Rp49Dwz+GGcQPTWqpczMDmO7ATQtG22t/FLWWmfpR8AmPp uXy+q8uMzECgMXMZbRZzRHnuz2fP4gNm2DhebLgA4h5wzLqFAtTMzT8NAcfpATiJYThi aNvqYgMOtCXEjV4jl6hzPXEtJTUU7UmlQW7kmZU6mq+6Am4CoIKilmS5E+/WD39GG2AE Q3EvvIxaEpnWKBuwLvoyIWv3pWl18EL7nrzskaTDol/b6cmhrU2jQKn+7gFplrBHXaPP rz+7lz8KRv8gGJVIjHLqslG9s8Kxbgyejwc6bQxFFyHnU4R1nEtvO9Ba7uIk6px/NN13 6ZuQ== MIME-Version: 1.0 Received: by 10.221.0.10 with SMTP id nk10mr7421964vcb.39.1352832636941; Tue, 13 Nov 2012 10:50:36 -0800 (PST) Received: by 10.52.0.193 with HTTP; Tue, 13 Nov 2012 10:50:36 -0800 (PST) In-Reply-To: References: Date: Tue, 13 Nov 2012 13:50:36 -0500 Message-ID: Subject: Re: Bug In Text Class - getLength() and getBytes().length are different. From: David Medinets To: dev@accumulo.apache.org Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Checked: Checked by ClamAV on apache.org That makes sense. I have resolved my issue by passing the Text.getLength() value along with Text.getBytes(). This works fine. Thanks. On Tue, Nov 13, 2012 at 1:23 PM, John Vines wrote: > This is not a bug. A Text object is a reusable object which prevents > repeated creation of byte arrays, so it will use the same byte array, > resizing it if necessary, and writing over the previous values. Doing any > operation based on Text.getBytes().length has a strong potential to provide > inaccurate results. Text.getLength() is the appropriate way to get the > length of the underlying byte array that you care about. > > John > > > On Tue, Nov 13, 2012 at 1:00 PM, David Medinets wrote: > >> 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 + "]"); >> } >> >> } >>