Index: lucene/core/src/java/org/apache/lucene/util/NamedSPILoader.java =================================================================== --- lucene/core/src/java/org/apache/lucene/util/NamedSPILoader.java (revision 1305754) +++ lucene/core/src/java/org/apache/lucene/util/NamedSPILoader.java (working copy) @@ -31,6 +31,12 @@ public final class NamedSPILoader implements Iterable { private final Map services; + + /** This field is a hack for LuceneTestCase to get access + * to the modifiable map (to work around bugs in IBM J9) */ + @SuppressWarnings("unused") + private final Map modifiableServices; + private final Class clazz; public NamedSPILoader(Class clazz) { @@ -46,6 +52,7 @@ services.put(name, service); } } + this.modifiableServices = services; // hack, remove when IBM J9 is fixed! this.services = Collections.unmodifiableMap(services); } Index: lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java =================================================================== --- lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java (revision 1305754) +++ lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java (working copy) @@ -327,6 +327,24 @@ 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 serviceMap = + (Map) modifiableServicesField.get(spiLoader); + if (!(Codec.forName("Lucene3x") instanceof PreFlexRWCodec)) { + 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."); + 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 codecs = Codec.availableCodecs();