adoptium / adoptium-support

For end-user problems reported with our binary distributions
Apache License 2.0
45 stars 15 forks source link

`error: bad file name` when trying to run chimera scripts using source code launcher #1106

Open mataha opened 2 months ago

mataha commented 2 months ago

Please provide a brief summary of the bug

Executing chimera scripts using the flexible launch protocol (as specified by JEP 463) and implicitly declared classes (same JEP) returns error: bad file name when run with the source code launcher (i.e. java --source <version> --enable-preview, see JEP 330) on Windows and Linux (but I'd imagine on all platforms).

Did you test with the latest update version?

Please provide steps to reproduce where possible

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 Results

Write once, run anywhere

Actual Results

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

What Java Version are you using?

openjdk version "22.0.1"
2024-04-16 OpenJDK Runtime Environment Temurin-22.0.1+8 (build 22.0.1+8)
OpenJDK 64-Bit Server VM Temurin-22.0.1+8 (build 22.0.1+8, mixed mode, sharing)

What is your operating system and platform?

Windows:

$ ver
Microsoft Windows [Version 10.0.19045.4412]

Linux:

$ uname -a
Linux pc 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

How did you install Java?

Windows:

curl -fsSL -o installer.msi "https://github.com/adoptium/temurin22-binaries/releases/download/jdk-22.0.1%2B8/OpenJDK22U-jdk_x64_windows_hotspot_22.0.1_8.msi"
.\installer.msi

Linux:

apt install -y wget apt-transport-https gpg
wget -qO - "https://packages.adoptium.net/artifactory/api/gpg/key/public" | gpg --dearmor | tee /etc/apt/trusted.gpg.d/adoptium.gpg >/dev/null
echo "deb https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | tee /etc/apt/sources.list.d/adoptium.list
apt update
apt install temurin-22-jdk

Did it work before?

No.

Did you test with other Java versions?

Java 21 LTS

Addendum

Interestingly, when I discard the protocol and create a dedicated public class with main method that's public, static and accepts an array of strings as its first parameter, everything works correctly - proving the script itself is not at fault:

@/*/ '"' 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("")
public class Main {
    public static void main(String... args) {
        System.out.println("Write once, run anywhere");
    }
}
$ ./amber.cmd
Write once, run anywhere
karianna commented 2 months ago

Hi @mataha - you're best of posting this to amber dash dev at openjdk dot org

mataha commented 2 months ago

Hi @mataha - you're best of posting this to amber dash dev at openjdk dot org

Done.