Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Java21, the ConstPool API throws NPE for MethodParameters attributes without parameter names #462

Closed
wuwen5 opened this issue Oct 8, 2023 · 0 comments · Fixed by #463

Comments

@wuwen5
Copy link
Contributor

wuwen5 commented Oct 8, 2023

public void testJava21() throws NotFoundException {
        CtClass ctClass = sloader.get("sun.net.httpserver.ServerImpl$ReqRspTimeoutTask");
        ctClass.getClassFile().compact();
}
java.lang.NullPointerException: Cannot read field "string" because "utf" is null
	at javassist.bytecode.ConstPool.getUtf8Info(ConstPool.java:675)
	at javassist.bytecode.MethodParametersAttribute.copy(MethodParametersAttribute.java:90)
	at javassist.bytecode.AttributeInfo.copyAll(AttributeInfo.java:249)
	at javassist.bytecode.MethodInfo.compact(MethodInfo.java:157)
	at javassist.bytecode.ClassFile.compact(ClassFile.java:242)
	at javassist.JvstTest4.testJdk21(JvstTest4.java:1008)

An error occurred while processing MethodParametersAttribute

In the construction method of the inner class, there are MethodParameters attributes without parameter names.

MethodParameters:
      Name                           Flags
      <no name>                      final mandated

openjdk/jdk#13167 (comment)

And just to double-check, the JVMS does allow the parameter name information to be missing even if the access flags are defined: https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-4.html#jvms-4.7.24

name_index

The value of the name_index item must either be zero or a valid index into the constant_pool table.

If the value of the name_index item is zero, then this parameters element indicates a formal parameter with no name.

If the value of the name_index item is nonzero, the constant_pool entry at that index must be a CONSTANT_Utf8_info structure representing a valid unqualified name denoting a formal parameter ([§4.2.2](https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-4.html#jvms-4.2.2)).
@wuwen5 wuwen5 changed the title Failed to rebuild sun.net.httpserver.ServerImpl$ReqRspTimeoutTask class file for Jdk-21 In Java21, the ConstPool API throws NPE for MethodParameters attributes without parameter names Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant