lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
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 GMT
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) {}
+  }
+
 }



Mime
View raw message