IAE at CheckMethodAdapter.checkInternalName for non-Java-identifier name
Please use the following short program to reproduce the issue:
import org.objectweb.asm.signature.SignatureVisitor;
import org.objectweb.asm.signature.SignatureWriter;
import org.objectweb.asm.util.CheckSignatureAdapter;
public class Test {
public static void main(String[] args) {
SignatureWriter sw = new SignatureWriter();
SignatureVisitor sv = new CheckSignatureAdapter(CheckSignatureAdapter.CLASS_SIGNATURE,
sw).visitSuperclass();
sv.visitClassType("Foo Bar"); // note the whitespace in the name
sv.visitEnd();
System.out.println(sw.toString());
}
}
The program fails with the following exception:
java.lang.IllegalArgumentException: Invalid class name (must be a fully qualified class name in internal form):
Foo Bar
at org.objectweb.asm.util.CheckMethodAdapter.checkInternalName(CheckMethodAdapter.java:1354)
at org.objectweb.asm.util.CheckMethodAdapter.checkInternalName(CheckMethodAdapter.java:1321)
at org.objectweb.asm.util.CheckSignatureAdapter.visitClassType(CheckSignatureAdapter.java:280)
at Test.main(Test.java:25)
The exception is thrown because "Foo Bar" is not a Java identifier (see Character.isJavaIdentifier* calls in
CheckMethodAdapter.checkIdentifier). However, according to JVMS 8, §4.7.9.1
(https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.9.1), this name should be
allowed:
> The grammar includes the terminal symbol Identifier to denote the name of a type, field, method, formal
parameter, local variable, or type variable, as generated by a Java compiler. Such a name must not contain
any of the ASCII characters . ; [ / < > : (that is, the characters forbidden in method names (§4.2.2) and also
colon) but may contain characters that must not appear in an identifier in the Java programming language
(JLS §3.8).
I think CheckMethodAdapter.checkIdentifier should be fixed to support not only names which are Java
identifiers, but also other names allowed by the spec.
Note that this issue causes the Kotlin (kotlinlang.org) compiler to fail on a rather simple example:
https://youtrack.jetbrains.com/issue/KT-10494