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 2ABECD024 for ; Tue, 13 Nov 2012 18:13:56 +0000 (UTC) Received: (qmail 33053 invoked by uid 500); 13 Nov 2012 18:13:56 -0000 Delivered-To: apmail-accumulo-dev-archive@accumulo.apache.org Received: (qmail 33021 invoked by uid 500); 13 Nov 2012 18:13:56 -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 33011 invoked by uid 99); 13 Nov 2012 18:13:56 -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:13:56 +0000 X-ASF-Spam-Status: No, hits=2.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_SOFTFAIL X-Spam-Check-By: apache.org Received-SPF: softfail (nike.apache.org: transitioning domain of marc@accumulo.net does not designate 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:13:48 +0000 Received: by mail-vc0-f169.google.com with SMTP id fl17so9109284vcb.0 for ; Tue, 13 Nov 2012 10:13:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-originating-ip:in-reply-to:references:date :message-id:subject:from:to:content-type:x-gm-message-state; bh=lHknsmM2LYEbMkNtdtxaw2FPF/goFM9n8es4P3ZJ4rU=; b=NYBpRD+biu0WTU2MVLAKizLBbn0Tdiz5shXF20hPMAJWzzXxzKI3wt8MXeUpQTg9L6 maD4AuqeBrW92SvvsUVx5lFSRcSsyoBlvN/o5ci9y9+tIEsPMBzHDKWvMITSsq+JiyKf CKqjGhpRekOedDrN4U5kzHQKlkjpNa1dK+Jepiy2dRV/pRE10d1w6DgLYAz54v68Ls8K qzE+WjtVykVFqfb7du/l+lai2rI989NHJ/CVjm3IozVhb+VaxvGqqm+YEuMOU3QG9J0G fsyGc6hEiXFoIpqVLw146Dc8NpS2TZmDIblC4A8uxwsK+pBGGgBm3ZMHVjYEkC3SR5tm Mlsw== MIME-Version: 1.0 Received: by 10.52.98.105 with SMTP id eh9mr28523093vdb.11.1352830407455; Tue, 13 Nov 2012 10:13:27 -0800 (PST) Received: by 10.58.219.130 with HTTP; Tue, 13 Nov 2012 10:13:27 -0800 (PST) X-Originating-IP: [63.239.65.11] In-Reply-To: References: Date: Tue, 13 Nov 2012 13:13:27 -0500 Message-ID: Subject: Re: Bug In Text Class - getLength() and getBytes().length are different. From: Marc Parisi To: dev@accumulo.apache.org Content-Type: multipart/alternative; boundary=20cf307f319ee0b56404ce645fc4 X-Gm-Message-State: ALoCoQl83qxZAzwf5NBTjNjRsQkSNayhDMW6xy7vt66q5sf+0QRbwKes+DjttnL7eLoO/emOfXn0 X-Virus-Checked: Checked by ClamAV on apache.org --20cf307f319ee0b56404ce645fc4 Content-Type: text/plain; charset=ISO-8859-1 That's expected. As per http://docs.oracle.com/javase/6/docs/api/java/nio/Buffer.html, the byte buffer is created by the encoder, where there is no guarantee that the backing array's length would match the position ( or limit ). 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 + "]"); > } > > } > --20cf307f319ee0b56404ce645fc4--