Skip to content

Conversation

@sagar-h007
Copy link

@sagar-h007 sagar-h007 commented Jan 30, 2026

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

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

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.

@github-actions
Copy link

github-actions bot commented Feb 2, 2026

PR Health

License Headers ✔️
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/hooks_runner/test_data/download_assets/hook/build.dart
pkgs/jni/test/debug_release_test.dart
pkgs/objective_c/example/command_line/lib/main.dart
pkgs/objective_c/lib/src/ns_input_stream.dart

This check can be disabled by tagging the PR with skip-license-check.

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.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
jni Breaking 0.15.2 0.15.3-wip 0.15.3-wip ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

Copy link
Contributor

@liamappelbe liamappelbe left a 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.

@sagar-h007
Copy link
Author

@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.

@liamappelbe
Copy link
Contributor

I’ll run the code generation script and check in the regenerated JNI bindings

I don't see any updates to the generated bindings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[jni] Add null checks before calling methods

2 participants