Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
9.0
-
None
-
New
Description
We currently have our own implementation of the service loader standard (SPI) fo several reasons:
(1) In some older JDKs the order of classpath was not respected and this lead to wrong order of codecs implementing the same SPI name. This caused tests to sometimes use wrong class (we had this in Lucene 4 where we had a test-only read/write Lucene3 codec that was listed before the read-only one). That's no longer an issue, the order of loading does not matter. In addition, Java now does everything correct.
(2) In Analysis, we require SPI classes to have a constructor taking args (a Map of params in our case). We also extract the NAME from a static field. Standard service loader does not support this, it tries to instantiate the class with default ctor.
With Java 9+, the ServiceLoader now has a stream() method that allows to filter and preprocess classes: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/ServiceLoader.html#stream()
This allows us to use the new interface and just get the loaded class (which may come from module-info.class or a conventional SPI file): https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/ServiceLoader.Provider.html#type()
This change allows us to convert Lucene to modules listing all SPIs in the module-info.java.
Attachments
Issue Links
- breaks
-
LUCENE-10101 getField vs getDeclaredField in analysis SPI
- Closed
- is required by
-
LUCENE-9623 Add module descriptor (module-info.java) to lucene jars
- Resolved
- relates to
-
SOLR-14362 Tests no longer run with whitespace in Solr's checkout directory
- Resolved
- links to