Skip to content
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

[jni] Add the ability to check if a JObject is a subclass of a Java class. #1943

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

brianquinlan
Copy link
Contributor

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

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

Copy link

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
jni Non-Breaking 0.13.0 0.14.0-wip 0.13.1 ✔️
Changelog Entry ✔️
Package Changed Files

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

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 symbols
jni _ReferenceType
_opaque_pthread_mutex_t
_opaque_pthread_cond_t
_Dart_FinalizableHandle

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

License Headers ✔️
// Copyright (c) 2025, 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/jni/lib/src/third_party/generated_bindings.dart
pkgs/objective_c/lib/src/ns_input_stream.dart

@coveralls
Copy link

coveralls commented Jan 24, 2025

Coverage Status

coverage: 87.7% (+0.02%) from 87.681%
when pulling a317633 on brianquinlan:check
into 6456d48 on dart-lang:main.

Copy link
Member

@HosseinYousefi HosseinYousefi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice changes! Thanks Brian! I added a few small comments.

pkgs/jni/CHANGELOG.md Outdated Show resolved Hide resolved
T as<T extends JObject?>(
JObjType<T> type, {
bool releaseOriginal = false,
}) {
assert(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I had used assert here was not to do the type check in release mode.

Fetching the jclass and calling instanceof might be expensive if we perform a lot of castings.

Maybe we can have an unsafe flag which is false by default and if true will not do the checking?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should be safe by default.

I'd suggest that we do not offer an unsafe option unless we find a need for it. Put I'd be fine having a unsafeCast option, if you'd like me to add one.

pkgs/jni/lib/src/jobject.dart Show resolved Hide resolved
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.

3 participants