error: bad file name on chimera scripts using JEP 463
Mateusz Kazimierczuk
mataha at protonmail.com
Mon Jun 3 14:46:23 UTC 2024
Hello,
I originally raised this on adoptium-support issue tracker, but was advised to
post here instead (https://github.com/adoptium/adoptium-support/issues/1106).
Chimera scripts that take advantage of JEP 463 return error: bad file name when
executed with the source code launcher. Tested with 22.0.1 on Windows and Linux,
but I would imagine it's the same on other platforms.
amber.cmd:
@/*/ '"' 2>/dev/null || true #" 2>nul || setlocal && echo off && goto :cmd.exe
exec java --source 22 --enable-preview "${0}" "${@}"
exit
:cmd.exe
(for /f delims^= %%c in (^""%ComSpec%"^") do (goto) 2>nul || title^ %%~c) ^
&& java --source 22 --enable-preview "%~dpnx0" %*
goto :EOF
@/*/SafeVarargs
static void main(String... args) {
System.out.println("Write once, run anywhere");
}
Windows:
.\amber.cmd
Linux:
./amber.cmd
Expected result:
Write once, run anywhere
Actual result:
C:\Users\user\amber.cmd:1: error: bad file name: amber.cmd
@/*/ '"' 2>/dev/null || true #" 2>nul || setlocal && echo off && goto :cmd.exe
^
1 error
error: compilation failed
I don't believe the script itself is at fault - the following compiles normally:
@/*/ '"' 2>/dev/null || true #" 2>nul || setlocal && echo off && goto :cmd.exe
exec java --source 22 --enable-preview "${0}" "${@}"
exit
:cmd.exe
(for /f delims^= %%c in (^""%ComSpec%"^") do (goto) 2>nul || title^ %%~c) ^
&& java --source 22 --enable-preview "%~dpnx0" %*
goto :EOF
@/*/SuppressWarnings("unused")
public class Main {
public static void main(String... args) {
System.out.println("Write once, run anywhere");
}
}
$ .\amber.cmd
Write once, run anywhere
Best regards,
Mateusz Kazimierczuk
(By the way - I can't express how excited I am for JEP 477. The nature of these
scripts makes adding import statements impossible, as a file has to start with
"@/*/", at which point it's too late to import anything - only fully-qualified
names work. Implicit java.base import removes much of the verbosity. Thanks!)
More information about the amber-dev
mailing list