JVM 尖括号中的标识符导致内部方法错误
Identifiers in angle brackets on the JVM causing Internal Method error
以下代码使用名为 <traitinit>
的方法,但被 JVM 拒绝并带有 VerifyError
:
class Foo
{
static void `<traitinit>`() // pseudocode identifier, not possible in Java
{
}
static void test()
{
`<traitinit>`() // call the <traitinit> method
}
}
错误:
java.lang.VerifyError: Illegal call to internal method
Exception Details:
Location:
foo/bar/Foo.test()V @5: invokestatic
Reason:
Error exists in the bytecode
由于 JVM 已经使用 <init>
和 <clinit>
作为构造函数和 class 初始化程序,这似乎是一个合理的错误消息。但是,JVM 规范中是否有任何部分明确定义了 internal method
是什么?我猜它只保留了上面的两个特定标识符,但事实并非如此。
我自己找到了 JVM 规范的相关部分 (§4.2.2. Unqualified Names):
4.2.2. Unqualified Names
Names of methods, fields, local variables, and formal parameters are stored as unqualified names. An unqualified name must contain at least one Unicode code point and must not contain any of the ASCII characters . ; [ / (that is, period or semicolon or left square bracket or forward slash).
Method names are further constrained so that, with the exception of the special method names <init>
and <clinit>
(§2.9), they must not contain the ASCII characters < or > (that is, left angle bracket or right angle bracket).
(强调我的)
以下代码使用名为 <traitinit>
的方法,但被 JVM 拒绝并带有 VerifyError
:
class Foo
{
static void `<traitinit>`() // pseudocode identifier, not possible in Java
{
}
static void test()
{
`<traitinit>`() // call the <traitinit> method
}
}
错误:
java.lang.VerifyError: Illegal call to internal method
Exception Details:
Location:
foo/bar/Foo.test()V @5: invokestatic
Reason:
Error exists in the bytecode
由于 JVM 已经使用 <init>
和 <clinit>
作为构造函数和 class 初始化程序,这似乎是一个合理的错误消息。但是,JVM 规范中是否有任何部分明确定义了 internal method
是什么?我猜它只保留了上面的两个特定标识符,但事实并非如此。
我自己找到了 JVM 规范的相关部分 (§4.2.2. Unqualified Names):
4.2.2. Unqualified Names
Names of methods, fields, local variables, and formal parameters are stored as unqualified names. An unqualified name must contain at least one Unicode code point and must not contain any of the ASCII characters . ; [ / (that is, period or semicolon or left square bracket or forward slash).
Method names are further constrained so that, with the exception of the special method names
<init>
and<clinit>
(§2.9), they must not contain the ASCII characters < or > (that is, left angle bracket or right angle bracket).
(强调我的)