From 202d3af9d0b5d9a2d262625c51ae7407487f6e65 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Fri, 1 Mar 2013 13:12:16 +0000 Subject: [PATCH] LUCENE-4808: Add workaround for a JDK 8 "class library bug" which is still under discussion and may *not* be fixed git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1451584 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/analysis/core/TestRandomChains.java | 6 ++++-- .../apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java | 4 +++- .../solr/client/solrj/beans/DocumentObjectBinder.java | 4 +++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java index b100b8d6752..26f550dd064 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java @@ -252,12 +252,14 @@ public class TestRandomChains extends BaseTokenStreamTestCase { tokenfilters = new ArrayList>(); charfilters = new ArrayList>(); for (final Class c : analysisClasses) { + // TODO: Fix below code to use c.isAnnotationPresent(). It was changed + // to the null check to work around a bug in JDK 8 b78 (see LUCENE-4808). final int modifiers = c.getModifiers(); if ( // don't waste time with abstract classes or deprecated known-buggy ones Modifier.isAbstract(modifiers) || !Modifier.isPublic(modifiers) || c.isSynthetic() || c.isAnonymousClass() || c.isMemberClass() || c.isInterface() - || c.isAnnotationPresent(Deprecated.class) + || c.getAnnotation(Deprecated.class) != null || !(Tokenizer.class.isAssignableFrom(c) || TokenFilter.class.isAssignableFrom(c) || CharFilter.class.isAssignableFrom(c)) ) { continue; @@ -265,7 +267,7 @@ public class TestRandomChains extends BaseTokenStreamTestCase { for (final Constructor ctor : c.getConstructors()) { // don't test synthetic or deprecated ctors, they likely have known bugs: - if (ctor.isSynthetic() || ctor.isAnnotationPresent(Deprecated.class) || brokenConstructors.get(ctor) == ALWAYS) { + if (ctor.isSynthetic() || ctor.getAnnotation(Deprecated.class) != null || brokenConstructors.get(ctor) == ALWAYS) { continue; } if (Tokenizer.class.isAssignableFrom(c)) { diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java b/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java index fddb55011d6..7ae72338e87 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java +++ b/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java @@ -131,7 +131,9 @@ final class TestRuleSetupAndRestoreClassEnv extends AbstractBeforeAfterRule { Class targetClass = RandomizedContext.current().getTargetClass(); avoidCodecs = new HashSet(); - if (targetClass.isAnnotationPresent(SuppressCodecs.class)) { + // TODO: Fix below code to use c.isAnnotationPresent(). It was changed + // to the null check to work around a bug in JDK 8 b78 (see LUCENE-4808). + if (targetClass.getAnnotation(SuppressCodecs.class) != null) { SuppressCodecs a = targetClass.getAnnotation(SuppressCodecs.class); avoidCodecs.addAll(Arrays.asList(a.value())); } diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/beans/DocumentObjectBinder.java b/solr/solrj/src/java/org/apache/solr/client/solrj/beans/DocumentObjectBinder.java index b772ea04bad..ca84edbf335 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/beans/DocumentObjectBinder.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/beans/DocumentObjectBinder.java @@ -114,7 +114,9 @@ public class DocumentObjectBinder { } for (AccessibleObject member : members) { - if (member.isAnnotationPresent(Field.class)) { + // TODO: Fix below code to use c.isAnnotationPresent(). It was changed + // to the null check to work around a bug in JDK 8 b78 (see LUCENE-4808). + if (member.getAnnotation(Field.class) != null) { member.setAccessible(true); fields.add(new DocField(member)); }