Return-Path: Delivered-To: apmail-lucene-java-commits-archive@www.apache.org Received: (qmail 93181 invoked from network); 22 Nov 2009 13:53:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 22 Nov 2009 13:53:00 -0000 Received: (qmail 89938 invoked by uid 500); 22 Nov 2009 13:52:59 -0000 Delivered-To: apmail-lucene-java-commits-archive@lucene.apache.org Received: (qmail 89849 invoked by uid 500); 22 Nov 2009 13:52:59 -0000 Mailing-List: contact java-commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-dev@lucene.apache.org Delivered-To: mailing list java-commits@lucene.apache.org Received: (qmail 89840 invoked by uid 99); 22 Nov 2009 13:52:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 22 Nov 2009 13:52:59 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 22 Nov 2009 13:52:57 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C30C023888CF; Sun, 22 Nov 2009 13:52:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r883077 - in /lucene/java/branches/lucene_2_9: CHANGES.txt src/java/org/apache/lucene/util/AttributeSource.java src/test/org/apache/lucene/util/TestAttributeSource.java Date: Sun, 22 Nov 2009 13:52:35 -0000 To: java-commits@lucene.apache.org From: uschindler@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091122135235.C30C023888CF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: uschindler Date: Sun Nov 22 13:52:35 2009 New Revision: 883077 URL: http://svn.apache.org/viewvc?rev=883077&view=rev Log: LUCENE-2088: Merge to 2.9 Modified: lucene/java/branches/lucene_2_9/CHANGES.txt lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/util/AttributeSource.java lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/util/TestAttributeSource.java Modified: lucene/java/branches/lucene_2_9/CHANGES.txt URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/CHANGES.txt?rev=883077&r1=883076&r2=883077&view=diff ============================================================================== --- lucene/java/branches/lucene_2_9/CHANGES.txt (original) +++ lucene/java/branches/lucene_2_9/CHANGES.txt Sun Nov 22 13:52:35 2009 @@ -9,6 +9,9 @@ infoStream on IndexWriter and then add an empty document and commit (Shai Erera via Mike McCandless) + * LUCENE-2088: addAttribute() should only accept interfaces that + extend Attribute. (Shai Erera, Uwe Schindler) + ======================= Release 2.9.1 2009-11-06 ======================= Changes in backwards compatibility policy Modified: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/util/AttributeSource.java URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/util/AttributeSource.java?rev=883077&r1=883076&r2=883077&view=diff ============================================================================== --- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/util/AttributeSource.java (original) +++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/util/AttributeSource.java Sun Nov 22 13:52:35 2009 @@ -221,6 +221,12 @@ public Attribute addAttribute(Class attClass) { final Attribute att = (Attribute) attributes.get(attClass); if (att == null) { + if (!(attClass.isInterface() && Attribute.class.isAssignableFrom(attClass))) { + throw new IllegalArgumentException( + "addAttribute() only accepts an interface that extends Attribute, but " + + attClass.getName() + " does not fulfil this contract." + ); + } final AttributeImpl attImpl = this.factory.createAttributeInstance(attClass); addAttributeImpl(attImpl); return attImpl; Modified: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/util/TestAttributeSource.java URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/util/TestAttributeSource.java?rev=883077&r1=883076&r2=883077&view=diff ============================================================================== --- lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/util/TestAttributeSource.java (original) +++ lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/util/TestAttributeSource.java Sun Nov 22 13:52:35 2009 @@ -125,4 +125,18 @@ assertEquals("Token should only printed once", "("+tok.toString()+")", src.toString()); } + public void testInvalidArguments() throws Exception { + try { + AttributeSource src = new AttributeSource(); + src.addAttribute(Token.class); + fail("Should throw IllegalArgumentException"); + } catch (IllegalArgumentException iae) {} + + try { + AttributeSource src = new AttributeSource(); + src.addAttribute(Iterator.class); + fail("Should throw IllegalArgumentException"); + } catch (IllegalArgumentException iae) {} + } + }