JEP proposed to target JDK 11: 330: Launch Single-File Source-Code Programs

Volker Simonis volker.simonis at gmail.com
Fri May 18 06:05:01 UTC 2018


Hi,

I fully assist Roman and his proposal. I actually proposed this myself
during the initial proposal of the JEP [1] but my request was rejected
by Brian because they don't seem to want to change the JLS for this
feature. To cite him:

"Its simpler than that.  There are NO changes to the JLS, nor even any
(IIRC) changes to the compiler.  This is all in the command-line
launcher.  This is not a Java language feature. The scope is JDK, not
SE."

I'm still unhappy about that decision (because of the obvious
arguments mentioned by Roman) but if the community finally decides to
implement this feature without changing the JLS the JEP should at
least mention that explicitly in a "Non-Goals" section (e.g. something
like "It is out of scope of this JEP to maintain compatibility between
a Java source file as specified by the JLS and a source files which
are intended to be executed by the single file source code launcher").

Also notice that the shebang problem is not the only source of
incompatibility, but also the proposal that "the compiler does not
enforce the optional restriction defined at the end of JLS §7.6, that
a type in a named package should exist in a file whose name is
composed from the type name followed by the .java extension". The
restriction is "optional", but to my knowledge still widely adapted
(and I'm not sure, but this may still require a change to the current
compiler in contrast to what Brian mentioned in the earlier
conversation).

Thank you and best regards,
Volker

[1] http://mail.openjdk.java.net/pipermail/jdk-dev/2018-February/thread.html#718

On Thu, May 17, 2018 at 11:19 PM, Roman Kennke <roman at kennke.org> wrote:
> Yes, something like this.
>
> A little bit more broadly speaking, in order to make it consistent, make
> javac:
> - accept and ignore #! in the first line
> - don't enforce source filename convention as usual
> - expect main method, etc, as outlined in the JEP
>
> in other words: don't do the trickery of filtering etc in the launcher,
> but in the compiler itself.
>
> Roman
>
>> What about special-casing javac to interpret #! as a single-line
>> comment marker (synonym for //), for the first line of an input file,
>> and nowhere else?
>>
>> Thanks,
>>
>> Ben
>>
>> On Thu, May 17, 2018 at 9:50 PM, Roman Kennke <roman at kennke.org> wrote:
>>> Am 17.05.2018 um 22:12 schrieb mark.reinhold at oracle.com:
>>>> The following JEP is proposed to target JDK 11:
>>>>
>>>>   330: Launch Single-File Source-Code Programs
>>>>        http://openjdk.java.net/jeps/330
>>>>
>>>> Feedback on this proposal is more than welcome, as are reasoned
>>>> objections.  If no such objections are raised by 23:00 UTC on Thursday,
>>>> 24 May, or if they're raised and then satisfactorily answered, then
>>>> per the JEP 2.0 process proposal [1] I'll target this JEP to JDK 11.
>>>>
>>>> - Mark
>>>>
>>>>
>>>> [1] http://cr.openjdk.java.net/~mr/jep/jep-2.0-02.html
>>>>
>>>
>>> I like this proposal.
>>>
>>> I have a question about the shebang support though. If I write a
>>> sourcefile Test.java like this:
>>>
>>> #!/usr/bin/java
>>>
>>> public class Test {
>>>     public static void main(String[] args) {
>>>         System.out.println("Hello");
>>>     }
>>> }
>>>
>>> ... then it's not a valid Java source file anymore, and (currently)
>>> rejected by javac. I see that it is not relevant for the intended use
>>> because the java launcher would strip the first line (except for the
>>> newline). I still find it odd.
>>>
>>> In particular, it may end up confusing for the growing experience:
>>> - people who start learning Java using this single-source feature will
>>> find that shebang 'Java scripts' don't actually compile when passed to
>>> the Java compiler
>>> - the little Java script turns out to be 'too slow', hey, let's compile
>>> it. Oops, doesn't work.
>>> - the little Java scipt has grown to complicated and needs additional
>>> classes, but doesn't compile.
>>> - editors/IDEs might (rightly) flag it as errors
>>>
>>> etc
>>>
>>> I wonder if it might be reasonable to extend the JLS to allow for
>>> shebang support too? Or maybe even don't extend the JLS but make
>>> compilers behave nicely anyway? At the very least, there should be some
>>> language in the JEP that mentions this issue. It is a complication that
>>> seems more important than the mentioned "HelloWorld"-package with "java"
>>> classname.
>>>
>>> Best regards, Roman
>>>
>>
>
>


More information about the jdk-dev mailing list