jvm spec class name restrictions

46 views
Skip to first unread message

Jochen Theodorou

unread,
Dec 13, 2016, 1:22:42 PM12/13/16
to JVM Languages
Hi all,

I am looking, but somehow not finding, a complete description of how a
classname of a current class has to be according to the JVM. I am asking
especially because I met a case in which the 2 was tried as class name
and the verification of the class failed (1.8 update 65). And since
something like Foo2 is a valid name I strongly assume 2 is basically a
valid character. Now 2 is not a valid java identifier and such, but does
the class name really have to follow the JLS rules here?

Anyone able to help me with some references in the spec that explain this?

bye Jochen

Rahul Muttineni

unread,
Dec 14, 2016, 7:20:24 AM12/14/16
to JVM Languages
Hi Jochen,

The JVM specification allows pretty much anything that can be encoded in Modified-UTF8. If you want to run your generated classes directly on the JVM, pretty much any name will do. But if you want the classes that you are generating to be importable from Java via javac, you need to follow the JLS.

For what purpose are you wondering about the naming? We might be able to help you better if you tell us.

Hope that helps!
Rahul

Remi Forax

unread,
Dec 14, 2016, 7:30:03 AM12/14/16
to jvm-la...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "JVM Languages" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jvm-language...@googlegroups.com.
To post to this group, send email to jvm-la...@googlegroups.com.
Visit this group at https://groups.google.com/group/jvm-languages.
For more options, visit https://groups.google.com/d/optout.

Jochen Theodorou

unread,
Dec 14, 2016, 9:39:24 AM12/14/16
to jvm-la...@googlegroups.com


On 14.12.2016 13:20, Rahul Muttineni wrote:
> Hi Jochen,
>
> The JVM specification allows pretty much anything that can be encoded in
> Modified-UTF8. If you want to run your generated classes directly on the
> JVM, pretty much any name will do. But if you want the classes that you
> are generating to be importable from Java via javac, you need to follow
> the JLS.
>
> For what purpose are you wondering about the naming? We might be able to
> help you better if you tell us.

In Groovy somebody made a script 2.groovy, which the Groovy compiler
compiled to 2.class and the JVM then refused to verify. So I was
wondering about the naming rules. Sure, I know about the basic rules of
/;[... but why is 2 as name not allowed. The only possible reason I
could find was that 2 is no valid identifier in Java, but that seemed to
me to be a wrong rule, since the JLS sould not define the JVMS.

In that manner... tanks Remi for
see
http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.2,
but I don't see there why 2 is not allowed as class name... are am I blind?

bye Jochen

Rahul Muttineni

unread,
Dec 14, 2016, 1:00:48 PM12/14/16
to JVM Languages
2.class works perfectly, see the following Gist:

https://gist.github.com/rahulmutt/b54412607904601e2412f9f9b89fd163

Can you share the precise verification error? I think the problem is on the Groovy side rather than the JVM side.

Hope that helps!
Rahul
Reply all
Reply to author
Forward
0 new messages