Return-Path: Delivered-To: apmail-cassandra-user-archive@www.apache.org Received: (qmail 52822 invoked from network); 11 Jun 2010 23:28:14 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 11 Jun 2010 23:28:14 -0000 Received: (qmail 52808 invoked by uid 500); 11 Jun 2010 23:28:13 -0000 Delivered-To: apmail-cassandra-user-archive@cassandra.apache.org Received: (qmail 52764 invoked by uid 500); 11 Jun 2010 23:28:12 -0000 Mailing-List: contact user-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cassandra.apache.org Delivered-To: mailing list user@cassandra.apache.org Received: (qmail 52756 invoked by uid 99); 11 Jun 2010 23:28:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Jun 2010 23:28:12 +0000 X-ASF-Spam-Status: No, hits=-0.1 required=10.0 tests=AWL,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jbellis@gmail.com designates 74.125.82.44 as permitted sender) Received: from [74.125.82.44] (HELO mail-ww0-f44.google.com) (74.125.82.44) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Jun 2010 23:28:07 +0000 Received: by wwc33 with SMTP id 33so1279221wwc.31 for ; Fri, 11 Jun 2010 16:27:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=r5WYQc2/Qp8mVCQ+enGJVu6aJEMZnnEyFWYhbE/PHlA=; b=F1+GseuBE0q8fmUVSYYw6S5t4gmazlbO8OtcH7ZiPHLcBPfD+yVNLXOG/J1fz6Hlm2 QsME8z8kbPfF00TKU/i7DcKXzDzRrTeAA0Tyiduc/8ZtMinFtz2K9GNfOLeLHpcW/j11 mgTtRe6NRHafEvVng3LVbY5W4B8ls6RlW/zjI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=Oa6zd9oBRciLeTaJnilA/MxpJmmXpN5GnEgfpElFiquRnNnrheoFxnGW44idq1qb5v 59pn0x6QoeMPCgpoAD9etO+oZLXgLj4MdnCiBUSUl4uZ73A5wf1ohwR7XdBVHEAZIKC2 kwsLgKmFl7JnA2y7fmn0wQEu4N3jiFmE1A7c0= Received: by 10.216.85.71 with SMTP id t49mr544474wee.19.1276298866095; Fri, 11 Jun 2010 16:27:46 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.17.197 with HTTP; Fri, 11 Jun 2010 16:27:26 -0700 (PDT) In-Reply-To: References: From: Jonathan Ellis Date: Fri, 11 Jun 2010 16:27:26 -0700 Message-ID: Subject: Re: CLI failure due to default constructor in Types To: user@cassandra.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable The types should be singletons. Jeremy has submitted a patch fixing the CL= I. On Fri, Jun 11, 2010 at 2:01 PM, Eben Hewitt wrote: > Hi Everyone > I am wondering why default visibility constructors were added to each of = the > *Type classes in the db.marshal package? If I'm understanding right, this > breaks the CLI. > Explanation: > This is the original UTF8Type class from 0.6.2, which worked: > import java.io.UnsupportedEncodingException; > public class UTF8Type extends AbstractType > { > =A0=A0 =A0public int compare(byte[] o1, byte[] o2) > =A0=A0 =A0{ > =A0=A0 =A0 =A0 =A0try > =A0=A0 =A0 =A0 =A0{ > =A0=A0 =A0 =A0 =A0 =A0 =A0return new String(o1, "UTF-8").compareTo(new St= ring(o2, > "UTF-8")); > =A0=A0 =A0 =A0 =A0} > =A0=A0 =A0 =A0 =A0catch (UnsupportedEncodingException e) > =A0=A0 =A0 =A0 =A0{ > =A0=A0 =A0 =A0 =A0 =A0 =A0throw new RuntimeException(e); > =A0=A0 =A0 =A0 =A0} > =A0=A0 =A0} > =A0=A0 =A0public String getString(byte[] bytes) > =A0=A0 =A0{ > =A0=A0 =A0 =A0 =A0try > =A0=A0 =A0 =A0 =A0{ > =A0=A0 =A0 =A0 =A0 =A0 =A0return new String(bytes, "UTF-8"); > =A0=A0 =A0 =A0 =A0} > =A0=A0 =A0 =A0 =A0catch (UnsupportedEncodingException e) > =A0=A0 =A0 =A0 =A0{ > =A0=A0 =A0 =A0 =A0 =A0 =A0throw new RuntimeException(e); > =A0=A0 =A0 =A0 =A0} > =A0=A0 =A0} > } > > This is the UTF8Type class from the trunk and at least back to > 2010-06-05_12-31-16, which does not work: > import java.io.UnsupportedEncodingException; > public class UTF8Type extends AbstractType > { > =A0=A0 =A0public static final UTF8Type instance =3D new UTF8Type(); > =A0=A0 =A0UTF8Type() {} // singleton > =A0=A0 =A0public int compare(byte[] o1, byte[] o2) > =A0=A0 =A0{ > =A0=A0 =A0 =A0 =A0try > =A0=A0 =A0 =A0 =A0{ > =A0=A0 =A0 =A0 =A0 =A0 =A0return new String(o1, "UTF-8").compareTo(new St= ring(o2, > "UTF-8")); > =A0=A0 =A0 =A0 =A0} > =A0=A0 =A0 =A0 =A0catch (UnsupportedEncodingException e) > =A0=A0 =A0 =A0 =A0{ > =A0=A0 =A0 =A0 =A0 =A0 =A0throw new RuntimeException(e); > =A0=A0 =A0 =A0 =A0} > =A0=A0 =A0} > =A0=A0 =A0public String getString(byte[] bytes) > =A0=A0 =A0{ > =A0=A0 =A0 =A0 =A0try > =A0=A0 =A0 =A0 =A0{ > =A0=A0 =A0 =A0 =A0 =A0 =A0return new String(bytes, "UTF-8"); > =A0=A0 =A0 =A0 =A0} > =A0=A0 =A0 =A0 =A0catch (UnsupportedEncodingException e) > =A0=A0 =A0 =A0 =A0{ > =A0=A0 =A0 =A0 =A0 =A0 =A0throw new RuntimeException(e); > =A0=A0 =A0 =A0 =A0} > =A0=A0 =A0} > } > > The difference is that after 0.6.2, these two lines were added: > =A0=A0 =A0public static final UTF8Type instance =3D new UTF8Type(); > =A0=A0 =A0UTF8Type() {} // singleton > This causes the CLI to fail on gets on both Linux and Windows: > [default@Keyspace1] set Standard2['mykey']['mycol']=3D'My value' > Value inserted. > [default@Keyspace1] get Standard2['mykey']['mycol'] > Exception Class org.apache.cassandra.cli.CliClient can not access a membe= r > of class org.apache.cassandra.db.marshal.UTF8 > Type with modifiers "" > [default@Keyspace1] > > As you know, the Exception means that some classloader can't work with th= e > constructor with default (reduced) visibility. > So some code is definitely relying on the instance field, but it seems th= at > some other client code also relies on the (implicit) public constructor? > This is the same for all types that have similar "singleton" code added; = I > use UTF8Type as representative example. > So I wonder what the reason was for preventing the implicit public > constructor by reducing visibility this way. Ostensibly, it's to provide = a > Singleton, > but because the constructor is not marked private, this is not a true > singleton anyway,=A0and because there are no instance fields in any of th= ese > classes, everything's method local, there's nothing to be a Singleton abo= ut. > So what's the presumed Singleton part, even if it didn't break stuff? > I'm not sure what the benefit is, and this appears to be a bug. Perhaps I > misunderstand. > The following illustrates that removing this constructor, whose value is = not > immediately clear to begin with, fixes the problem: > Type 'help' or '?' for help. Type 'quit' or 'exit' to quit. > [default@unknown] use Keyspace1 > Authenticated to keyspace: Keyspace1 > [default@Keyspace1] set Standard2['k']['c']=3D'v' > Value inserted. > [default@Keyspace1] get Standard2['k']['c'] > ******************* ---->>> GETTING STRING WITH MODIFIED CODE. > =3D> (column=3Dc, value=3Dv, timestamp=3D1276287830318000) > [default@Keyspace1] > > But that may not be desired, and perhaps the real solution is to update > something in the CLI code that's using reflection. > Should I file a bug and, unless I don't understand the benefit of this, > supply the (very modest) fix for each of the types? Or is this known and > understood, simply broken for now, and going somewhere good? If so, where= ? > Thanks for such a great project and community. > Eben > -- > "In science there are no 'depths'; there is surface everywhere." > --Rudolph Carnap > --=20 Jonathan Ellis Project Chair, Apache Cassandra co-founder of Riptano, the source for professional Cassandra support http://riptano.com