swiftlang / swiftlang/swift-java

jextract accepts an empty javaPackage and emits invalid Java source in JNI and FFM modes

Open
#919 0 comments 0 reactions 0 assignees View on GitHub

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-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:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.