Skip to content

SourceVersion.isName() may fail on JREs without java.compiler module #375

Description

@elharo

Affected version: all

Description:

MavenArchiver.isValidModuleName() at line 109 uses javax.lang.model.SourceVersion.isName():

static boolean isValidModuleName(String name) {
    return SourceVersion.isName(name);
}

This class lives in the java.compiler module, which is not resolved in minimal JRE images (e.g., custom jlink images that exclude it). SourceVersion.isName() is called unconditionally in doCreateArchive() at line 569 whenever an Automatic-Module-Name attribute is present:

if (automaticModuleName != null) {
    if (automaticModuleName.isEmpty()) {
        manifest.getMainSection().removeAttribute("Automatic-Module-Name");
    } else if (!isValidModuleName(automaticModuleName)) {
        throw new ManifestException("Invalid automatic module name...");
    }
}

On stripped-down JREs, this can throw NoClassDefFoundError at runtime when creating archives that include an Automatic-Module-Name.

Low priority — uncommon JRE configuration, but worth noting for users targeting minimal containers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:minorMinor loss of function, or other problem where easy workaround is present

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions