-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GR-49816] Throw exception for null pointers passed to RuntimeJNIAccess / RuntimeReflection register methods #6985
[GR-49816] Throw exception for null pointers passed to RuntimeJNIAccess / RuntimeReflection register methods #6985
Conversation
d680bbd
to
78c9301
Compare
+1 for throwing NPEs, so that users are forced to look into registrations and other API calls that do nothing (e.g., when a class/field/method lookup returned |
f8a0c45
to
2b0e34c
Compare
@fniephaus this one slept through the cracks. I have updated it to thrown |
null
pointer in RuntimeJNIAccess
/ RuntimeReflection
register
methods
sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/ReflectionRegistry.java
Outdated
Show resolved
Hide resolved
...vm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ConditionalConfigurationRegistry.java
Outdated
Show resolved
Hide resolved
sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/ReflectionRegistry.java
Outdated
Show resolved
Hide resolved
2b0e34c
to
6ba9fb4
Compare
substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/ReflectionRegistrationTest.java
Outdated
Show resolved
Hide resolved
6ba9fb4
to
448711d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Could you please fix the style gate? |
Don't allow null values to be passed to the `register` method of `RuntimeJNIAccess` and `RuntimeReflection`. Since these are public APIs GraalVM should either handle null values (by ignoring them in this case) or throw a `NullPointerException` before creating an asynchronous task to perform the registration in the analysis, which then results in `NullPointerException`s being thrown later when it's no longer possible to understand where the null value originate from.
448711d
to
e6c12dd
Compare
Done |
Thank you greatly for this fix. LGTM. |
Not before the register methods, which can miss cases, nor later on in a runnable.
I discussed this internally and changed the PR as follows:
|
Sounds good, are you going to create a different PR or force push on this?
That makes sense, this way it won't cover only the public facing APIs.
Doesn't this result in iterating over the arrays twice? Once for the check and another for the runnables?
Indeed. Thanks for noticing and fixing this. |
Yes, but there are no guarantees when the runnables run. What if they run later on in some other thread? |
This is only a concern because we are using Streams instead of iterators (for loop), e.g. here, right? Given that the arrays being iterated are not expected to be that big, what's the benefit of using streams? |
I just pushed my changes manually.
I'm not using streams for the null-checks. I didn't touch the other code you references. |
Looks good to me. Thank you Fabio. Well runnables are inevitable in |
What do you mean? For reachability handlers, some runnables may never run (if something did not get reachable). We should still fail if |
Yes, I agree. Sorry if it was not clear. |
Don't allow null values to be passed to the
register
method ofRuntimeJNIAccess
andRuntimeReflection
. Since these are public APIs GraalVM should either handle null values (by ignoring them in this case) or throw aNullPointerException
before creating an asynchronous task to perform the registration in the analysis, which then results inNullPointerException
s being thrown later when it's no longer possible to understand where the null value originate from.Closes: quarkusio/quarkus#34698
If accepted, it would also be good to get this backported to 23.1 and 23.0 (and 22.3?).