Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-3927: allow running trunk tests with IBM JRE

Robert Muir2185d9f55e90
diff --git a/lucene/core/src/java/org/apache/lucene/util/NamedSPILoader.java b/lucene/core/src/java/org/apache/lucene/util/NamedSPILoader.java
index 0f24daa5c15..ed75f5b5cde 100644
--- a/lucene/core/src/java/org/apache/lucene/util/NamedSPILoader.java
+++ b/lucene/core/src/java/org/apache/lucene/util/NamedSPILoader.java
@@ -31,6 +31,14 @@ import java.util.ServiceLoader;
public final class NamedSPILoader<S extends NamedSPILoader.NamedSPI> implements Iterable<S> {
private final Map<String,S> services;
+
+ /** This field is a hack for LuceneTestCase to get access
+ * to the modifiable map (to work around bugs in IBM J9) */
+ @SuppressWarnings("unused")
+ @Deprecated
+ // Hackidy-Häck-Hack for bugs in IBM J9 ServiceLoader
+ private final Map<String,S> modifiableServices;
+
private final Class<S> clazz;
public NamedSPILoader(Class<S> clazz) {
@@ -46,6 +54,7 @@ public final class NamedSPILoader<S extends NamedSPILoader.NamedSPI> implements
services.put(name, service);
}
}
+ this.modifiableServices = services; // hack, remove when IBM J9 is fixed!
this.services = Collections.unmodifiableMap(services);
}
diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
index 497a46adfc4..2c67aec8fd5 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
@@ -327,6 +327,32 @@ public abstract class LuceneTestCase extends Assert {
System.setProperty("solr.directoryFactory", "org.apache.solr.core.MockDirectoryFactory");
}
+ // enable the Lucene 3.x PreflexRW codec explicitly, to work around bugs in IBM J9 / Harmony ServiceLoader:
+ try {
+ final java.lang.reflect.Field spiLoaderField = Codec.class.getDeclaredField("loader");
+ spiLoaderField.setAccessible(true);
+ final Object spiLoader = spiLoaderField.get(null);
+ final java.lang.reflect.Field modifiableServicesField = NamedSPILoader.class.getDeclaredField("modifiableServices");
+ modifiableServicesField.setAccessible(true);
+ @SuppressWarnings({"unchecked","rawtypes"}) final Map<String,Codec> serviceMap =
+ (Map) modifiableServicesField.get(spiLoader);
+ if (!(Codec.forName("Lucene3x") instanceof PreFlexRWCodec)) {
+ if (Constants.JAVA_VENDOR.startsWith("IBM")) {
+ // definitely a buggy version
+ System.err.println("ERROR: Your VM's java.util.ServiceLoader implementation is buggy"+
+ " and does not respect classpath order, please report this to the vendor.");
+ } else {
+ // could just be a classpath issue
+ System.err.println("ERROR: fix your classpath to have tests-framework.jar before lucene-core.jar!"+
+ " If you have already done this, then your VM's java.util.ServiceLoader implementation is buggy"+
+ " and does not respect classpath order, please report this to the vendor.");
+ }
+ serviceMap.put("Lucene3x", new PreFlexRWCodec());
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("Cannot access internals of Codec and NamedSPILoader classes", e);
+ }
+
// if verbose: print some debugging stuff about which codecs are loaded
if (VERBOSE) {
Set<String> codecs = Codec.availableCodecs();