CheckedMethodAdapter rejects valid Java and JVM identifiers with surrogate characters
Consider the following valid Java code:
public class 𝔻 {
public 𝔻() {}
𝔻 foo() {
return new 𝔻();
}
}
It uses unicode character U+1D53B which is an alphanumeric character and a valid Java identifier name and Java identifier start. However, when you run the following code with ASM:
public class Check {
public static void main(String[] args) throws IOException {
CheckClassAdapter adapter = new CheckClassAdapter(null);
// put your actual path here
new ClassReader(new FileInputStream("build/classes/java/main/\uD835\uDD3B.class")).accept(adapter, 0);
}
}
Then it crashes with the following exception:
Exception in thread "main" java.lang.IllegalArgumentException: Invalid class name (must be a fully qualified class name in internal form): 𝔻
at org.objectweb.asm.util.CheckMethodAdapter.checkInternalName(Unknown Source)
at org.objectweb.asm.util.CheckMethodAdapter.checkInternalName(Unknown Source)
at org.objectweb.asm.util.CheckClassAdapter.visit(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at Check.main(Check.java:10)
The reason is that U+1D53B is encoded in UTF-16 with a surrogate pair and it is not handled correctly by CheckMethodAdapter.checkInternalName