ChrisHegarty commented on code in PR #12677:
URL: https://github.com/apache/lucene/pull/12677#discussion_r1359850988


##########
lucene/core/src/java/org/apache/lucene/internal/vectorization/VectorizationProvider.java:
##########
@@ -120,24 +124,21 @@ static VectorizationProvider lookup(boolean testMode) {
     } else if (runtimeVersion >= 22) {
       LOG.warning(
           "You are running with Java 22 or later. To make full use of the 
Vector API, please update Apache Lucene.");
-    } else if (vectorModulePresentAndReadable()) {
+    } else if (lookupVectorModule().isPresent()) {
       LOG.warning(
           "Java vector incubator module was enabled by command line flags, but 
your Java version is too old: "
               + runtimeVersion);
     }
     return new DefaultVectorizationProvider();
   }
 
-  private static boolean vectorModulePresentAndReadable() {
-    var opt =
-        ModuleLayer.boot().modules().stream()
-            .filter(m -> m.getName().equals("jdk.incubator.vector"))
-            .findFirst();
-    if (opt.isPresent()) {
-      VectorizationProvider.class.getModule().addReads(opt.get());
-      return true;
-    }
-    return false;
+  /**
+   * Looks up the vector module from Lucene's {@link ModuleLayer} or the root 
layer (if unnamed).
+   */
+  private static Optional<Module> lookupVectorModule() {
+    return 
Optional.ofNullable(VectorizationProvider.class.getModule().getLayer())
+        .orElse(ModuleLayer.boot())
+        .findModule("jdk.incubator.vector");

Review Comment:
   This seems fine.  However, in practical terms the `jdk.incubator.vector` 
module will only ever appear in the boot layer, because of the qualified 
exports that it has from `java.base` (these exports will be dropped from 
`java.base` if the vector module is not present in the same layer).  That said, 
it's not impossible to get this to work, and your changes are reasonable.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to