Summary
jextract accepts a missing or empty javaPackage and exits successfully, but emits invalid Java source code.
This behavior is reproducible with JDK 25 in both JNI and FFM modes.
Reproduction
swift-java jextract \
--mode jni \
--swift-module MySwiftLibrary \
--java-package '' \
--input-swift Samples/SwiftJavaExtractJNISampleApp/Sources/MySwiftLibrary \
--output-swift /tmp/generated-swift \
--output-java /tmp/generated-java
The same result occurs with --mode ffm.
Environment used for reproduction:
openjdk version "25.0.4.1"
javac 25.0.4.1
Actual behavior
jextract completes successfully and generates Java files containing:
Compiling the generated source with JDK 25 fails with:
error: <identifier> expected
package ;
^
In JNI mode, generated native entry points also contain names such as:
FFM mode does not generate JNI entry points, but still produces the invalid package ; declaration.
The same code path can be reached when:
--java-package is omitted
javaPackage is set to "" in swift-java.config
The CLI option is optional, and missing values are eventually passed to both generators as an empty string.
Expected behavior
jextract should not report successful generation while emitting Java source that cannot be compiled.
The intended behavior for an empty or missing javaPackage needs to be clarified.
Points for discussion before fix
- Should
javaPackage be required for jextract?
- How should missing, empty, whitespace-only, or syntactically invalid Java package names be handled?
- If empty or invalid packages are unsupported, should generation fail before writing any output?
- If Java's unnamed/default package should be supported, how should package declarations, output paths, and JNI name mangling be defined?
- Should the behavior be identical between JNI and FFM modes?
Relevant code:
Summary
jextractaccepts a missing or emptyjavaPackageand exits successfully, but emits invalid Java source code.This behavior is reproducible with JDK 25 in both JNI and FFM modes.
Reproduction
swift-java jextract \ --mode jni \ --swift-module MySwiftLibrary \ --java-package '' \ --input-swift Samples/SwiftJavaExtractJNISampleApp/Sources/MySwiftLibrary \ --output-swift /tmp/generated-swift \ --output-java /tmp/generated-javaThe same result occurs with
--mode ffm.Environment used for reproduction:
Actual behavior
jextractcompletes successfully and generates Java files containing:package ;Compiling the generated source with JDK 25 fails with:
In JNI mode, generated native entry points also contain names such as:
FFM mode does not generate JNI entry points, but still produces the invalid
package ;declaration.The same code path can be reached when:
--java-packageis omittedjavaPackageis set to""inswift-java.configThe CLI option is optional, and missing values are eventually passed to both generators as an empty string.
Expected behavior
jextractshould not report successful generation while emitting Java source that cannot be compiled.The intended behavior for an empty or missing
javaPackageneeds to be clarified.Points for discussion before fix
javaPackagebe required forjextract?Relevant code:
Swift2Java.swiftJExtractCommand.swift