Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support JEP 330 "shebang" headers #1214

Open
vorburger opened this issue Dec 29, 2024 · 3 comments
Open

Support JEP 330 "shebang" headers #1214

vorburger opened this issue Dec 29, 2024 · 3 comments

Comments

@vorburger
Copy link
Member

vorburger commented Dec 29, 2024

I'm toying (more "for fun") with https://openjdk.org/jeps/330 in enola-dev/enola#971:

I am using https://www.jbang.dev, but this issue doesn't really have anything to do with that (JBang) per se:

For the following content of learnenola.java which (at least as I understand it) is technically "valid standard Java syntax" per JEP 330:

#!/usr/bin/env jbang

import static java.lang.System.out;

public class learnenola {

    public static void main(String... args) {
        out.println("Hello World");
    }
}

google-java-format currently fails like this:

$ ./google-java-format_linux-x86-64 --aosp --lines 1:11 learnenola.java

<stdin>:1:1: error: illegal character: '#'
#!/usr/bin/env jbang
^
<stdin>:1:3: error: class, interface, enum, or record expected
#!/usr/bin/env jbang
  ^
 Command failed: ./google-java-format_linux-x86-64 --aosp --lines 1:13 -
<stdin>:1:1: error: illegal character: '#'
#!/usr/bin/env jbang
^
<stdin>:1:3: error: class, interface, enum, or record expected
#!/usr/bin/env jbang
  ^

See also https://www.jbang.dev/documentation/guide/latest/faq.html for some further background if needed.

PS: I've opened another issue #1215 for something that's a separate problem related to "special" (non-shebang) /// comments.

@vorburger
Copy link
Member Author

vorburger commented Dec 29, 2024

which (at least as I understand it) is technically "valid standard Java syntax" per JEP 330

FYI both Visual Studio Code and IntelliJ IDEA don't really like this syntax either (VSC, which uses JDT, just says "Syntax error on tokens, delete these tokens", and IJ says "Shebang mechanism in .java files is not permitted" (which surprised me given that this jetbrains.com post says it should work; but possibly I just couldn't figure out the right language level support Settings).

But be that (current Editor support) as it may, per JEP 330 it's still valid Java syntax, so (in a perfect world... 🍭 ) google-java-format should not choke on it.

@vorburger
Copy link
Member Author

FTR This is on v1.25.1, which is the 2nd most recent release today; looking at the 1.25.2 Release Notes, I have no reason to believe that this (just) got fixed.

@cushon
Copy link
Collaborator

cushon commented Jan 3, 2025

technically "valid standard Java syntax" per JEP 330

I'm not sure that's right, as I understand it JEP 330 is exclusively a Java launcher (bin/java) feature, and mentions that

It is not a goal to change either the Java Language Specification (JLS) or javac to accommodate shebang file

javac also rejects these files:

$ javac T.java
T.java:1: error: illegal character: '#'
#!/usr/bin/env jbang
^
T.java:1: error: class, interface, enum, or record expected
#!/usr/bin/env jbang
  ^
2 errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants