You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2010/11/11 22:18:08 UTC

svn commit: r1034137 - in /lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene: analysis/tokenattributes/TermAttributeImpl.java util/AttributeSource.java

Author: uschindler
Date: Thu Nov 11 21:18:07 2010
New Revision: 1034137

URL: http://svn.apache.org/viewvc?rev=1034137&view=rev
Log:
SOLR-2234: Fix CTA backwards layer to enforce correct implementation for deprecated TermAttribute

Modified:
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/analysis/tokenattributes/TermAttributeImpl.java
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/AttributeSource.java

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/analysis/tokenattributes/TermAttributeImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/analysis/tokenattributes/TermAttributeImpl.java?rev=1034137&r1=1034136&r2=1034137&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/analysis/tokenattributes/TermAttributeImpl.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/analysis/tokenattributes/TermAttributeImpl.java Thu Nov 11 21:18:07 2010
@@ -19,8 +19,8 @@ package org.apache.lucene.analysis.token
 
 /**
  * The term text of a Token.
- * @deprecated This class is only available for AttributeSource
- * to be able to load an old TermAttribute implementation class.
+ * @deprecated This class is not used anymore. The backwards layer in
+ * AttributeFactory uses the replacement implementation.
  */
 @Deprecated
 public class TermAttributeImpl extends CharTermAttributeImpl {

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/AttributeSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/AttributeSource.java?rev=1034137&r1=1034136&r2=1034137&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/AttributeSource.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/AttributeSource.java Thu Nov 11 21:18:07 2010
@@ -28,6 +28,8 @@ import java.util.Map;
 import java.util.Map.Entry;
 
 import org.apache.lucene.analysis.TokenStream; // for javadocs
+import org.apache.lucene.analysis.tokenattributes.TermAttribute;
+import org.apache.lucene.analysis.tokenattributes.CharTermAttributeImpl;
 
 /**
  * An AttributeSource contains a list of different {@link AttributeImpl}s,
@@ -77,11 +79,17 @@ public class AttributeSource {
           Class<? extends AttributeImpl> clazz = (ref == null) ? null : ref.get();
           if (clazz == null) {
             try {
+              // TODO: Remove when TermAttribute is removed!
+              // This is a "sophisticated backwards compatibility hack"
+              // (enforce new impl for this deprecated att):
+              if (TermAttribute.class.equals(attClass)) {
+                clazz = CharTermAttributeImpl.class;
+              } else {
+                clazz = Class.forName(attClass.getName() + "Impl", true, attClass.getClassLoader())
+                  .asSubclass(AttributeImpl.class);
+              }
               attClassImplMap.put(attClass,
-                new WeakReference<Class<? extends AttributeImpl>>(
-                  clazz = Class.forName(attClass.getName() + "Impl", true, attClass.getClassLoader())
-                  .asSubclass(AttributeImpl.class)
-                )
+                new WeakReference<Class<? extends AttributeImpl>>(clazz)
               );
             } catch (ClassNotFoundException e) {
               throw new IllegalArgumentException("Could not find implementing class for " + attClass.getName());