Skip to content

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

Description

@Hokila

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:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions