-
Notifications
You must be signed in to change notification settings - Fork 103
[jni] Throw NullPointerException for null JNI parameters #3031
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
base: main
Are you sure you want to change the base?
Conversation
PR HealthLicense Headers ✔️
All source files should start with a license header. Unrelated files missing license headers
This check can be disabled by tagging the PR with API leaks ✔️The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
This check can be disabled by tagging the PR with Breaking changes ✔️
This check can be disabled by tagging the PR with Changelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. This check can be disabled by tagging the PR with |
liamappelbe
left a comment
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.
It looks like you're changing the code-gen script that generates the JNI bindings, which is fine. But users don't run that code-gen script, they just use the generated bindings, so make sure to run the code-gen and check in the result.
Also, make sure to dart format and dart analyze your code before you upload it.
|
@liamappelbe I’ll run the code generation script and check in the regenerated JNI bindings. I’ll also make sure everything is formatted and dart analyze is clean before updating the PR. |
I don't see any updates to the generated bindings. |
This PR adds generated null checks to JNI wrapper functions and throws a proper NullPointerException when required JNI parameters are null. This prevents native crashes and ensures errors are surfaced to Dart as JniException instead of failing silently.
What I did
•Updated the JNI C wrapper generator to add null checks for JNI reference and ID parameters
•Changed null handling to actively throw java/lang/NullPointerException
•Skipped null checks for JNI functions that are defined to accept null
•Regenerated JNI wrapper C files
•Added tests to verify null parameters now result in Dart-side exceptions
What this does
Before, passing null into some generated JNI calls could crash native code or return incorrect results. With this change, null inputs are detected early and reported as exceptions, making failures safer and easier to debug.
Fixes: #2943
Contribution guidelines:
dart format.Many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.
Note: The Dart team is trialing Gemini Code Assist. Don't take its comments as final Dart team feedback. Use the suggestions if they're helpful; otherwise, wait for a human reviewer.