Skip to content

Commit e35dd51

Browse files
committed
fix(run): remove module guard and match java -jar native-access errors
1 parent 52f14a2 commit e35dd51

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/main/java/dev/jbang/source/generators/JarCmdGenerator.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,20 @@ protected List<String> generateCommandLineList() throws IOException {
9898
Jdk jdk = project.projectJdk();
9999
String javacmd = JavaUtil.resolveInJavaHome("java", jdk);
100100

101-
if (!runAsModule && jdk.majorVersion() >= 9) {
101+
if (jdk.majorVersion() >= 9) {
102102
addAllUnnamedManifestOptions(optionalArgs, project.getManifestAttributes().get(Project.ATTR_ADD_OPENS),
103103
"--add-opens=");
104104
addAllUnnamedManifestOptions(optionalArgs, project.getManifestAttributes().get(Project.ATTR_ADD_EXPORTS),
105105
"--add-exports=");
106106
}
107107

108-
if (!runAsModule && jdk.majorVersion() >= 22) {
108+
if (jdk.majorVersion() >= 22) {
109109
String nativeAccess = project.getManifestAttributes().get(Project.ATTR_ENABLE_NATIVE_ACCESS);
110110
if (nativeAccess != null) {
111-
nativeAccess = nativeAccess.trim();
112111
if ("ALL-UNNAMED".equals(nativeAccess)) {
113112
optionalArgs.add("--enable-native-access=" + nativeAccess);
114113
} else {
115-
throw new ExitException(BaseCommand.EXIT_INVALID_INPUT,
114+
throw new ExitException(1,
116115
"Invalid value for manifest attribute Enable-Native-Access: " + nativeAccess);
117116
}
118117
}

src/test/java/dev/jbang/cli/TestRun.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2656,6 +2656,7 @@ void testRejectsInvalidEnableNativeAccess(@TempDir Path output) throws IOExcepti
26562656
Project code = pb.build(jar.toString());
26572657

26582658
ExitException ex = assertThrows(ExitException.class, () -> CmdGenerator.builder(code).build().generate());
2659+
assertThat(ex.getStatus(), equalTo(1));
26592660
assertThat(ex.getMessage(), containsString("Enable-Native-Access"));
26602661
}
26612662

@@ -2762,4 +2763,3 @@ private Path createJar(Path outputDir, String buildJdk, Map<String, String> mani
27622763
return jar;
27632764
}
27642765
}
2765-

0 commit comments

Comments
 (0)