swiftlang / swiftlang/swift-java
jextract accepts an empty javaPackage and emits invalid Java source in JNI and FFM modes
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 1.2k
- Forks
- 123
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 16
Description
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:
package ;
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:
Java__MyEntity__...
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.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
javaPackagebe required forjextract? - 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:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the --java-package handling in JExtractCommand.swift and Swift2Java.swift, then inspect the JNI and FFM Java printers and String+JavaNaming.swift. Reproduce the issue in both modes with an empty or omitted package, and compare generated output with javac. Done requires a decided policy for missing or invalid packages and consistent behavior before output is written.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100