Jussi said:
Where does JLS say the class should be public? I failed to find it in
the index and in the following page that explains how a program is
executed.
I don't remember ever seeing any suggestion that the class has to be public
either. Section 12.1.4 of the JLS states what that the main(String[]) method
must be public, static, and void, but makes no mention of conditions that the
class itself must meet.
In any case, it's far from clear that that section is intended to be
normative -- it is embedded in a whole sequence of text which is clearly
descriptive rather than normative (and which explicitly references the JVM
spec, describing itself as "an overview"). In my opinion, whether or not it
is /intended/ to be normative, it damn-well /shouldn't/ be normative as
written; because if it was it would be requiring a behaviour that no complete
Java implementation has ever exhibited, nor ever will. The public static void
main(String[]) thing is just how one way of launching Java programs works -- it
is incidental to that specific program, and other programs can and do work in
different ways. That has been true ever since JDK 1.0.2, and probably before.
FWIW, the code for the java.exe launcher is simple, and it would be trivial to
add a check that the entry-point class is public (and perhaps that it's a
top-level class too). Similar trivial code already exists only a few lines
away to ensure that main() is public. So, if this is a bug, there hardly seems
to be a plausible reason for it to have remained unfixed for so long.
-- chris