Skip to content

Android code quality improvements#17636

Merged
kirklandsign merged 6 commits intomainfrom
android/fix-check-after-use
Feb 23, 2026
Merged

Android code quality improvements#17636
kirklandsign merged 6 commits intomainfrom
android/fix-check-after-use

Conversation

@kirklandsign
Copy link
Copy Markdown
Contributor

@kirklandsign kirklandsign commented Feb 23, 2026

Summary

  • Fix check-after-use bug in JNI scalar type lookup: move .count() check
    before .at() so unsupported scalar types throw a Java exception instead
    of C++ std::out_of_range
  • Fix initHybridnumThreads parameter name in Module.java native
    declaration
  • Fix missing space in getMethodMetadata() error message
  • Modernize build config: Java 11 source/target, remove dead
    root ext properties (minSdkVersion, targetSdkVersion, compileSdkVersion,
    buildToolsVersion), update test dependencies (junit 4.13.2,
    androidx.test.ext:junit 1.2.1, androidx.test:rules 1.6.1,
    commons-io 2.18.0)

Review order: jni_layer.cppModule.javabuild.gradle files.

Test plan

  • CI (existing unit + instrumentation tests cover the JNI and Module paths)
  • Build config changes are compile-time only; verified locally that Gradle
    sync succeeds

scalar_type_to_java_dtype.at(scalarType) throws std::out_of_range
for unknown types before the .count() guard on the next line can run,
making the error handling dead code. Move the .count() check before
.at() so unsupported scalar types throw a proper Java exception
instead of crashing.
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Feb 23, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/17636

Note: Links to docs will display an error until the docs builds have been completed.

❌ 3 New Failures, 51 Pending, 3 Unrelated Failures

As of commit 0521e2a with merge base cf08087 (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@kirklandsign kirklandsign marked this pull request as ready for review February 23, 2026 20:26
Copilot AI review requested due to automatic review settings February 23, 2026 20:26
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 23, 2026
@github-actions
Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical check-after-use bug in the JNI scalar type lookup code. The issue was that scalar_type_to_java_dtype.at(scalarType) was called before checking if the key exists in the map with .count(), causing the C++ code to throw an unhandled std::out_of_range exception and crash instead of throwing a proper Java exception.

Changes:

  • Move the .count() check before the .at() lookup to prevent crashes on unsupported scalar types
  • Update error message to display the actual scalar type value instead of an uninitialized jdtype variable
  • Enable proper Java exception handling for unsupported tensor scalar types

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kirklandsign kirklandsign changed the title Fix check-after-use bug in JNI scalar type lookup Android code quality improvements Feb 23, 2026
Remove dead root ext properties (minSdkVersion, targetSdkVersion,
compileSdkVersion, buildToolsVersion) that were unused by the module.
Copilot AI review requested due to automatic review settings February 23, 2026 21:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread extension/android/jni/jni_layer.cpp
throwExecutorchException only sets a pending Java exception and does not
abort C++ execution. Without an early return, subsequent code (e.g.
map::at()) can throw std::out_of_range before the JVM sees the pending
exception.
Copilot AI review requested due to automatic review settings February 23, 2026 22:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread extension/android/executorch_android/build.gradle
@kirklandsign kirklandsign merged commit c4e325d into main Feb 23, 2026
180 of 191 checks passed
@kirklandsign kirklandsign deleted the android/fix-check-after-use branch February 23, 2026 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants