Attempt to remove non-JNI local reference errors on Android
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 75/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Ruhig
- Tech-Stack
- android, swift
- Bereich
- mobile-dev
Rechercherichtung
Beginne bei JavaObjectHolder.init(object:environment:), wo eingehende jobject-Referenzen hochgestuft werden und die Warnung ausgelöst wird. Reproduziere die Android-JNI-Aufrufe auf dem Android-15-Emulator mit der FlutterSwift-Anwendung und überprüfe anschließend, dass häufig verwendete Platform-Channel-Message-Handler null "Attempt to remove non-JNI local reference"-Warnungen ausgeben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Using FlutterSwift with the latest swift-java and Android SDK, I see
2026-04-01 15:37:27.149 7457-7457 ktone.InfernoUI com.lukktone.InfernoUI W Attempt to remove non-JNI local reference
in the Android logs.
Proposed fix is to remove DeleteLocalRef on incoming references in JavaObjectHolder.init to fix Android JNI warnings. (This is by @ampcode-com, I haven't had a chance to review, I hate AI-generated PRs as much as the next person but I haven't had the cycles to look into the root cause myself yet.)
Root Cause
JavaObjectHolder.init(object:environment:) promotes the incoming jobject to a global reference via NewGlobalRef, then checks if the original is a local reference and calls DeleteLocalRef on it. This is problematic because:
-
JNI parameter references are not owned by native code. When Java calls a native method, the
jobjectparameters are local references managed by the JNI frame. The JNI specification states these are automatically cleaned up when the native method returns. Native code should not callDeleteLocalRefon them. -
ART's CheckJNI detects this. Android's runtime (ART) has CheckJNI enabled by default, which distinguishes between locally-created references (via
FindClass,NewObject, etc.) and parameter references. CallingDeleteLocalRefon a parameter reference triggers the warning. -
GetObjectRefTypereturnsJNILocalRefTypefor both cases, so the existing check cannot distinguish parameter references from locally-created references.
Fix
Remove the DeleteLocalRef call entirely. After NewGlobalRef creates a new strong reference to the Java object, the original local reference (whether a parameter or locally-created) will be cleaned up automatically when the JNI frame is popped. This is safe and correct per the JNI specification:
"Local references are valid for the duration of a native method call. They are freed automatically after the native method returns." — JNI Specification
The only scenario where explicit DeleteLocalRef is needed is to avoid local reference table overflow when creating many local references in a loop within a single native method call. JavaObjectHolder.init does not fall into this category.
Testing
Tested on Android 15 (API 36) emulator with a FlutterSwift application that makes frequent JNI calls (platform channel message handlers). Before the fix, every message handler invocation produced 1–3 "Attempt to remove non-JNI local reference" warnings. After the fix, zero warnings are emitted
- Vorherrschende Sprache
- Swift
- Sterne
- 1.3k
- Forks
- 127
- Ø Merge
- 2 T. 14 Std.
- Gemergte PRs (30 T.)
- 5
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus swiftlang/swift-java
-
wrap-java: Optional convenience methods can fail to compile when a parameter shadows the method nameOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
swiftlang/swift-java#945 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 56/100
swiftlang/swift-java#949 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
swiftlang/swift-java#948 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 54/100
swiftlang/swift-java#947 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 53/100
swiftlang/swift-java#946 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in swiftlang/swift-java
Ähnliche Issues
-
feat: 앱 정보에 개인정보처리방침과 고객지원 연결Evtl. vergeben @xrpjwk8 hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
DeveloperAcademy-POSTECH/2026-C6-A13-Hear-I-am#120 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
jaywcjlove/quick-rss#448 ·
-
Edit Space… → Save overwrites an imported space's SF Symbol icon with 🌱 and stacks both glyphsOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
VictorKildahl/cra#205 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
[Bug]: Intermittent failure in PathUtilsTests.testNewDirectoryIsExcludedAndExistingChoiceIsKeptOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
apple/container#2474 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
AttilaTheFun/visor#244 ·
Maintainer antworten meist innerhalb von 1 Tag