Skip to content

Conversation

@sidepelican
Copy link
Contributor

This PR fixes a compilation error in the generated JNI thunk code.

  • original code
public func throwsHello() throws -> String {
    return "Hello"
}
  • generated code
@_cdecl("Java_my_lib_AndroidSwift__00024throwsHello__")
public func Java_my_lib_AndroidSwift__00024throwsHello__(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass) -> jstring? {
  do {
    return try AndroidSwift.throwsHello().getJNIValue(in: environment)
  } catch {
    environment.throwAsException(error)
    return .jniPlaceholderValue // error: contextual member reference to static property 'jniPlaceholderValue' requires 'Self' constraint in the protocol extension
  }
} // printCDecl(_:javaMethodName:parentName:parameters:resultType:_:) @ JExtractSwiftLib/JNISwift2JavaGenerator+SwiftThunkPrinting.swift:725

jstring? does not have a .jniPlaceholderValue extension.
There might be other types with the same issue, but for now, I’ve only implemented a fix for String.

@sidepelican sidepelican requested a review from ktoso as a code owner January 20, 2026 07:53
Copy link
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

Nice, thank you!

@ktoso ktoso added feature:jextract Issues related to jextract-swift mode:jni labels Jan 20, 2026
@ktoso ktoso merged commit 614af0d into swiftlang:main Jan 20, 2026
49 checks passed
@sidepelican sidepelican deleted the fix_throws_string branch January 20, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature:jextract Issues related to jextract-swift mode:jni

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants