You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "cortlepp (via GitHub)" <gi...@apache.org> on 2026/03/20 10:06:17 UTC

[PR] Fix: don't force native access if disabled (#15815) [lucene]

cortlepp opened a new pull request, #15843:
URL: https://github.com/apache/lucene/pull/15843

   The current implementation of `PosixNativeAccess` always tries to use native access, even if this is disallowed by the JVM. This can lead to warnings on JDK24+ and will eventually be the default setting in future JVM versions. Additionally the current singleton implementation in `PosixNativeAccess` is problematic because it does the native setup during class initialization (`<clinit>`). This makes the timing of that setup unpredictable (because the JVM may load classes at any time, not just before first use) and can cause the entire application to fail if an exception is thrown (and not caught) during this setup (even if the application would work fine without native access).
   
   This PR:
   - changes the implementation to only attempt enabling native access if this is allowed by the running JVM
   - changes the singleton in `PosixNativeAccess` to use an enum pattern


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #15843:
URL: https://github.com/apache/lucene/pull/15843#issuecomment-4106515253

   Hi,
   In the other PR that will be merged soon, I changed the code a bit to not fail on RuntimeException. Theoretically under some circumstances it may fail with IllegalArgException, so the hole static block handles this.
   It won't catch and ignore Throwable or Errors as this is a no-go, also for static initializers.
   Uwe


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #15843:
URL: https://github.com/apache/lucene/pull/15843#discussion_r2965427247


##########
lucene/core/src/java/org/apache/lucene/store/PosixNativeAccess.java:
##########
@@ -79,14 +81,12 @@ static Optional<NativeAccess> getInstance() {
                   + "pass the following on command line: --enable-native-access=%s",
               Optional.ofNullable(PosixNativeAccess.class.getModule().getName())
                   .orElse("ALL-UNNAMED")));
-    } catch (RuntimeException | Error e) {

Review Comment:
   It is not brittle. The reason for the `catch (Throwable)` and the corresponding `catch (Runtime+Error)` is the general pattern used in Lucene when you execute a `MethodHandle` (here it happens when you get page size). As panama method handles by default never throw anything (thats defined in spec, the assertion is correct. But if you catch Throwable, you have to filter on RuntimException and Error to not swallow or convert the runtime exception tosomething else. Thats needed for correctness of code.
   
   It does not make it briddle. The same type of code is also used inside the JVM. That's how it should be. The feature is optional, but it the lookup is not briddle.
   
   There is actually a bug, but it is fixed here in #15844. It may catch on a JVM or platform that has no native support at all. It was caused by a refactoring done by @jpountz (see above).



-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #15843:
URL: https://github.com/apache/lucene/pull/15843#discussion_r2965427247


##########
lucene/core/src/java/org/apache/lucene/store/PosixNativeAccess.java:
##########
@@ -79,14 +81,12 @@ static Optional<NativeAccess> getInstance() {
                   + "pass the following on command line: --enable-native-access=%s",
               Optional.ofNullable(PosixNativeAccess.class.getModule().getName())
                   .orElse("ALL-UNNAMED")));
-    } catch (RuntimeException | Error e) {

Review Comment:
   It is not brittle. The reason for the `catch (Throwable)` and the corresponding `catch (Runtime+Error)` is the general pattern used in Lucene when you execute a `MethodHandle` (here it happens when you get page size). As panama method handles by default never throw anything (thats defined in spec, the assertion is correct. But if you catch Throwable, you have to filter on RuntimException and Error to not swallow or convert the runtime exception tosomething else. Thats needed for correctness of code.
   
   It does not make it briddle. The same type of code is also used inside the JVM. That's how it should be. The feature is optional, but it the lookup is not briddle.
   
   There is actually a bug, but it is fixed here. It may catch on a JVM or platform that has no native support at all. It was caused by a refactoring done by @jpountz (see above).



-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #15843:
URL: https://github.com/apache/lucene/pull/15843#issuecomment-4098262741

   Hi, 
   I checked how it is implemented inside the JVM. It is impossible to prevent the warning, unless you disable native access in Lucene by default. So you can work around only by enabling or disabling it. So I can't fix this inside Lucene code:
   
   The check for Module#isNativeAccessEnabled always returns false when the defaults are used and it is only enabled by the code.
   
   So actually the check you do in this PR breaks native access unless opted in.


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #15843:
URL: https://github.com/apache/lucene/pull/15843#discussion_r2965208027


##########
lucene/core/src/java/org/apache/lucene/store/PosixNativeAccess.java:
##########
@@ -79,14 +81,12 @@ static Optional<NativeAccess> getInstance() {
                   + "pass the following on command line: --enable-native-access=%s",
               Optional.ofNullable(PosixNativeAccess.class.getModule().getName())
                   .orElse("ALL-UNNAMED")));
-    } catch (RuntimeException | Error e) {

Review Comment:
   That wont happen because no method is marked as restricted. Try it out!



-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #15843:
URL: https://github.com/apache/lucene/pull/15843#discussion_r2965094524


##########
lucene/core/src/java/org/apache/lucene/store/PosixNativeAccess.java:
##########
@@ -28,6 +28,14 @@
 import java.util.logging.Logger;
 
 final class PosixNativeAccess extends NativeAccess {
+  private enum PosixNativeAccessSingletonHolder {
+    INSTANCE(constructInstance());
+    private Optional<NativeAccess> posixNativeAccess;

Review Comment:
   this field should be final



-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #15843:
URL: https://github.com/apache/lucene/pull/15843#issuecomment-4097305502

   Basically the current code should only be changed to have a possible `UnsupportedOperationException` handled also here:
   
   https://github.com/cortlepp/lucene/blob/3ba9a0736636e976677c4c29c351945b23dfee6c/lucene/core/src/java/org/apache/lucene/store/PosixNativeAccess.java#L63-L64
   
   So maybe move that down into the try-catch. Then it is safe for clinit. I don't see a reason for refactoring this otherwise.
   
   Logging the warning IF native access is disabled is actually wanted.


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #15843:
URL: https://github.com/apache/lucene/pull/15843#issuecomment-4097603521

   See #15844 for the only fix needed here. I will also add a comment in source code to explain why the catch blocks are required.
   
   I will close this issue as there is no problem. The code is not briddle and used in similar way at other static initializers.


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #15843:
URL: https://github.com/apache/lucene/pull/15843#discussion_r2965220784


##########
lucene/core/src/java/org/apache/lucene/store/PosixNativeAccess.java:
##########
@@ -79,14 +81,12 @@ static Optional<NativeAccess> getInstance() {
                   + "pass the following on command line: --enable-native-access=%s",
               Optional.ofNullable(PosixNativeAccess.class.getModule().getName())
                   .orElse("ALL-UNNAMED")));
-    } catch (RuntimeException | Error e) {

Review Comment:
   I'd only move the follwong to inside the try...catch
   
   https://github.com/cortlepp/lucene/blob/3ba9a0736636e976677c4c29c351945b23dfee6c/lucene/core/src/java/org/apache/lucene/store/PosixNativeAccess.java#L63-L64
   



-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #15843:
URL: https://github.com/apache/lucene/pull/15843#discussion_r2965427247


##########
lucene/core/src/java/org/apache/lucene/store/PosixNativeAccess.java:
##########
@@ -79,14 +81,12 @@ static Optional<NativeAccess> getInstance() {
                   + "pass the following on command line: --enable-native-access=%s",
               Optional.ofNullable(PosixNativeAccess.class.getModule().getName())
                   .orElse("ALL-UNNAMED")));
-    } catch (RuntimeException | Error e) {

Review Comment:
   It is not brittle. The reason for the `catch (Throwable)` and the corresponding `catch (Runtime+Error)` is the general pattern used in Lucene when you execute a `MethodHandle` (here it happens when you get page size). As panama method handles by default never throw anything (thats defined in spec, the assertion is correct. But if you catch Throwable, you have to filter on RuntimException and Error to not swallow or mis-rethrow the runtime exception. Thats needed for correctness of code.
   
   It does not make it briddle. The same type of code is also used inside the JVM. That's how it should be. The feature is optional, but it the lookup is not briddle.
   
   There is actually a bug, but it is fixed here. It may catch on a JVM or platform that has no native support at all. It was caused by a refactoring done by @jpountz (see above).



-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #15843:
URL: https://github.com/apache/lucene/pull/15843#discussion_r2965427247


##########
lucene/core/src/java/org/apache/lucene/store/PosixNativeAccess.java:
##########
@@ -79,14 +81,12 @@ static Optional<NativeAccess> getInstance() {
                   + "pass the following on command line: --enable-native-access=%s",
               Optional.ofNullable(PosixNativeAccess.class.getModule().getName())
                   .orElse("ALL-UNNAMED")));
-    } catch (RuntimeException | Error e) {

Review Comment:
   It is not brittle. The reason for the `catch (Throwable)` and the corresponding `catch (Runtime
   +Error)` is the general pattern used in Lucene when you execute a `MethodHandle`. As panama method handles by default never throw anything (thats defined in spec, the assertion is correct. But if you catch Throwable, you have to filter on RuntimException and Error to not swallow or mis-rethrow the runtime exception. Thats needed for correctness of code.
   
   It does not make it briddle. The same type of code is also used inside the JVM. That's how it should be. The feature is optional, but it the lookup is not briddle.
   
   There is actually a bug, but it is fixed here. It may catch on a JVM or platform that has no native support at all. It was caused by a refactoring done by @jpountz (see above).



-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #15843:
URL: https://github.com/apache/lucene/pull/15843#issuecomment-4097526990

   Actually: Your enum could also be accidentally loaded. The enum constants are also initialized on class loading so the same problems occur. So theres no reason to actually make a holder.


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler closed pull request #15843: Fix: don't force native access if disabled (#15815)
URL: https://github.com/apache/lucene/pull/15843


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "cortlepp (via GitHub)" <gi...@apache.org>.
cortlepp commented on PR #15843:
URL: https://github.com/apache/lucene/pull/15843#issuecomment-4097407440

   > I still don't think that the current code fails when native access is disabled. Have you tested this?
   
   It doesn't fail, that's not what I meant. If an exception is thrown for the 2nd/3rd catch block it will fail though and then you have the described class loading issues. My main argument is that the current implementation is brittle because it can lead to wider class loading issues for a feature that is strictly speaking optional, even on posix platforms. Besides I think that it is unwise to do the setup things we need to in `<clinit>` in general. Class loading may be triggered [by many things](https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-5.html#jvms-5.5), it may even be loaded by accident on incompatible platforms e.g. windows (so when `PosixNativeAccess` should never be loaded). The new implementation fixes that, which is why I'd really prefer this or a similar pattern.
   
   > Logging the warning IF native access is disabled is actually wanted.
   
   I kind of disagree with that, but it seems to be the general stance in Lucene so I've made my peace with it. My problem with the current implementation is that I can't suppress the warning because it always attempts the native access, which triggers a JVM warning (which I can't suppress) and then a log (which I can suppress). If I want to avoid the JVM warning I would have to add a JVM flag, which is hard in my deployment scenario where I don't have direct access to the JVM, we only provide the jar.
   
   > Can you add this to the 10.x changes list in this PR already. I will take care of the backport and add modifications to the "preview" compilation in Java 21. I will open a PR for that after we merged this.
   
   1. do you really mean 10.x, as you mentioned in it's current form this PR only works on JDK 22+
   2. As far as I understood the docs the changes.txt should only document api changes, this PR doesn't change any API (that I'm aware of)


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #15843:
URL: https://github.com/apache/lucene/pull/15843#issuecomment-4097248921

   In general this can only be applied to main branch (11.0), backporting to Lucene 10 is possible, but needs a bit more adaptions:
   
   We need to add class `java.lang.Module` to the stub apijar for compilation because the 
   `isNativeAccessEnabled()` enabled method is preview only, but luckily available in Java 21 and unmodified later. I can take care of this,
   
   I forgot to add this earlier (I had it on my "brain-only-TODO-list" but forgot about it).
   
   Can you add this to the 10.x changes list in this PR already. I will take care of the backport and add modifications to the "preview" compilation in Java 21. I will open a PR for that after we merged this.


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "cortlepp (via GitHub)" <gi...@apache.org>.
cortlepp commented on PR #15843:
URL: https://github.com/apache/lucene/pull/15843#issuecomment-4096993755

   @uschindler @jpountz friendly ping because you are the main authors of this file :smile: .


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #15843:
URL: https://github.com/apache/lucene/pull/15843#issuecomment-4098123603

   > @uschindler
   > 
   > > the warning isse is the same if you don't enable vectorization preview.
   > 
   > Sorry, but it really isn't because in the vectorization case I can silence the logger, in this case here my JVM will print the following:
   > 
   > ```
   > WARNING: A restricted method in java.lang.foreign.Linker has been called
   > WARNING: java.lang.foreign.Linker::downcallHandle has been called by org.apache.lucene.store.PosixNativeAccess in an unnamed module (file:/usr/local/tomcat/webapps/ROOT/WEB-INF/lib/lucene-core-10.4.0.jar)
   > WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
   > WARNING: Restricted methods will be blocked in a future release unless native access is enabled
   > ```
   
   That's the same for Vectorization, the only difference is that it only happens
   
   To get rid of the warning pass the correct command line parameter. This PR does not fix the issue. The easiest is to disallow or allow native access (see test config on other PR). It is not Lucene's problem how you configure your JVM.
   
   > > Actually: Your enum could also be accidentally loaded. The enum constants are also initialized on class loading so the same problems occur. So theres no reason to actually make a holder.
   > 
   > Yeah, you're right, my mistake. But IMO that means we should still change the current implementation, just not to an enum singleton holder but instead a double locking pattern (or something else that does not have the class loading issue).
   
   Why. There is no issue during class loading. If you are afraid you need to do this for every clinit anywhere in Lucene.
   
   It is impossible that the code fails after the other PR is merged. If an exception is thrown,  your JVM is broken anyways. Lucene is very strict on exceptions, e.g. we never ever catch Throwable and swallow or don't report. The patterns seen here is at many places, e.g. Panama vector init, Lucene 10 Mmap, Expressions module,... - we have many static initializers that may fail if your JVM is broken. The exception handling is always strict. We never ever intend to catch or swallow Throwable. It's always rethrowed if unknown, also in static initializers.
   
   Sorry, Uwe


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #15843:
URL: https://github.com/apache/lucene/pull/15843#issuecomment-4098134939

   In the other PR I will add some code to prevent the warning message on JVM startup.


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #15843:
URL: https://github.com/apache/lucene/pull/15843#issuecomment-4097255706

   P.S.: Nice Singleton style - I like it!


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #15843:
URL: https://github.com/apache/lucene/pull/15843#issuecomment-4097282396

   I still don't think that the current code fails when native access is disabled. Have you tested this.
   
   Actually it is intended to log warning, with your change the warning is no longer printed. In general I don't see a problem with current code. If you want to get rid of the warning, suppress it in your logging config.
   
   The current code is fine, but I don't understand why it fails. I have tested current code with disabled native access and it correctly logs a warning, so the clinit stuff is fine.


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #15843:
URL: https://github.com/apache/lucene/pull/15843#issuecomment-4097901780

   I tested all combinations in #15844. I look into adding integration test that spawns a JVM without native access. as a separate commit.


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "cortlepp (via GitHub)" <gi...@apache.org>.
cortlepp commented on PR #15843:
URL: https://github.com/apache/lucene/pull/15843#issuecomment-4098053250

   > the warning isse is the same if you don't enable vectorization preview.
   
   Sorry, but it really isn't because in the vectorization case I can silence the logger, in this case here my JVM will print the following:
   ```
   WARNING: A restricted method in java.lang.foreign.Linker has been called
   WARNING: java.lang.foreign.Linker::downcallHandle has been called by org.apache.lucene.store.PosixNativeAccess in an unnamed module (file:/usr/local/tomcat/webapps/ROOT/WEB-INF/lib/lucene-core-10.4.0.jar)
   WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
   WARNING: Restricted methods will be blocked in a future release unless native access is enabled
   ```
   
   > Actually: Your enum could also be accidentally loaded. The enum constants are also initialized on class loading so the same problems occur. So theres no reason to actually make a holder.
   
   Yeah, you're right, my mistake. But IMO that means we should still change the current implementation, just not to an enum singleton holder but instead a double locking pattern (or something else that does not have the class loading issue).


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "cortlepp (via GitHub)" <gi...@apache.org>.
cortlepp commented on code in PR #15843:
URL: https://github.com/apache/lucene/pull/15843#discussion_r2965203768


##########
lucene/core/src/java/org/apache/lucene/store/PosixNativeAccess.java:
##########
@@ -79,14 +81,12 @@ static Optional<NativeAccess> getInstance() {
                   + "pass the following on command line: --enable-native-access=%s",
               Optional.ofNullable(PosixNativeAccess.class.getModule().getName())
                   .orElse("ALL-UNNAMED")));
-    } catch (RuntimeException | Error e) {

Review Comment:
   > Can you explain why it may fail and lead to clinit problem and later ClassDefNotFoundExceptions?
   
   If one of these blocks is triggered, `PosixNativeAccess` will not be loaded. If that is the case, any invocation of `NativeAccess::getInstance()` will fail because it needs access to `PosixNativeAccess`.



-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #15843:
URL: https://github.com/apache/lucene/pull/15843#discussion_r2965213126


##########
lucene/core/src/java/org/apache/lucene/store/PosixNativeAccess.java:
##########
@@ -79,14 +81,12 @@ static Optional<NativeAccess> getInstance() {
                   + "pass the following on command line: --enable-native-access=%s",
               Optional.ofNullable(PosixNativeAccess.class.getModule().getName())
                   .orElse("ALL-UNNAMED")));
-    } catch (RuntimeException | Error e) {

Review Comment:
   If native access is disabled, the IllegalCallerException is catched. That's the only exception that can happen when native access is disabled.



-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "cortlepp (via GitHub)" <gi...@apache.org>.
cortlepp commented on code in PR #15843:
URL: https://github.com/apache/lucene/pull/15843#discussion_r2965305792


##########
lucene/core/src/java/org/apache/lucene/store/PosixNativeAccess.java:
##########
@@ -79,14 +81,12 @@ static Optional<NativeAccess> getInstance() {
                   + "pass the following on command line: --enable-native-access=%s",
               Optional.ofNullable(PosixNativeAccess.class.getModule().getName())
                   .orElse("ALL-UNNAMED")));
-    } catch (RuntimeException | Error e) {

Review Comment:
   > That wont happen because no method is marked as restricted.
   
   That may be, but it's very brittle. What is the purpose for those re-throws in the second and third catch? Also see my more general comment below, I just think that initializing the class this way, especially considering that its an optional feature on all platforms, can cause problems that are completely avoidable.



-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix: don't force native access if disabled (#15815) [lucene]

Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #15843:
URL: https://github.com/apache/lucene/pull/15843#issuecomment-4097480278

   Hi,
   the warning isse is the same if you don't enable vectorization preview. Lucene is written to actually "require" thos parts, but it works slower without. So we prefer to log a warning. If e.g., in Java 27, the JVM disables native access by default, we would like to avoid
   
   Actually the current code is a bit broken due to this change by @jpountz: https://github.com/cortlepp/lucene/commit/3003731aa94225b3a07cb9fb667fc8fd62bb2d10
   
   The first two lines of the static initializer must be inside the try...catch. The code is NOT briddle, sorry. The exception handling was done carefully and accoridng to the native access spec. We don't generally want to do anything like "catch (RuntimeException _)", because it would swallow an important exception. If the static initializer breaks, its a bug in the JVM and should fail.
   
   So IMHO, the change by @jpountz should be fixed to move the first two lines of the static initializer to the try/catch block. This is indeed a bug and may fail the startup - the UnsupportedOperationException is handled there.
   
   I can open a PR and merge this to fix this bug, but all the other code changes here are unneeded and theres no risk in the current code because all native access runtime Exceptions are handled according to the Panama Foreign spec.


-- 
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-unsubscribe@lucene.apache.org

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


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