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

fixes Issue 462 (In Java21, the ConstPool API throws NPE for MethodParameters attributes without parameter names) #463

Merged
merged 1 commit into from Dec 4, 2023

Conversation

wuwen5
Copy link
Contributor

@wuwen5 wuwen5 commented Oct 8, 2023

fix #462

package test4;
public class MethodParamInnerClassTest {
    class InnerClass implements Runnable {
        public void run() {
        }
    }
}

When compiling with Java21 (without the -parameters), the information is as follows

Classfile /Users/wuwen/opensource/javassist/temp/jdk21/MethodParamInnerClassTest$InnerClass.class
  Last modified 2023年10月8日; size 481 bytes
  SHA-256 checksum a40905df13d2760afd54f301c8ef0e06dd4f3a620b2e5946f363ed771172fc38
  Compiled from "MethodParamInnerClassTest.java"
class test4.MethodParamInnerClassTest$InnerClass implements java.lang.Runnable
  minor version: 0
  major version: 65
  flags: (0x0020) ACC_SUPER
  this_class: #7                          // test4/MethodParamInnerClassTest$InnerClass
  super_class: #2                         // java/lang/Object
  interfaces: 1, fields: 0, methods: 2, attributes: 3
Constant pool:
   #1 = Methodref          #2.#3          // java/lang/Object."<init>":()V
   #2 = Class              #4             // java/lang/Object
   #3 = NameAndType        #5:#6          // "<init>":()V
   #4 = Utf8               java/lang/Object
   #5 = Utf8               <init>
   #6 = Utf8               ()V
   #7 = Class              #8             // test4/MethodParamInnerClassTest$InnerClass
   #8 = Utf8               test4/MethodParamInnerClassTest$InnerClass
   #9 = Class              #10            // java/lang/Runnable
  #10 = Utf8               java/lang/Runnable
  #11 = Utf8               (Ltest4/MethodParamInnerClassTest;)V
  #12 = Utf8               Code
  #13 = Utf8               LineNumberTable
  #14 = Utf8               MethodParameters
  #15 = Utf8               run
  #16 = Utf8               SourceFile
  #17 = Utf8               MethodParamInnerClassTest.java
  #18 = Utf8               NestHost
  #19 = Class              #20            // test4/MethodParamInnerClassTest
  #20 = Utf8               test4/MethodParamInnerClassTest
  #21 = Utf8               InnerClasses
  #22 = Utf8               InnerClass
{
  test4.MethodParamInnerClassTest$InnerClass(test4.MethodParamInnerClassTest);
    descriptor: (Ltest4/MethodParamInnerClassTest;)V
    flags: (0x0000)
    Code:
      stack=1, locals=2, args_size=2
         0: aload_0
         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
         4: return
      LineNumberTable:
        line 5: 0
    MethodParameters:
      Name                           Flags
      <no name>                      final mandated


  public void run();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=0, locals=1, args_size=1
         0: return
      LineNumberTable:
        line 7: 0
}
SourceFile: "MethodParamInnerClassTest.java"
NestHost: class test4/MethodParamInnerClassTest
InnerClasses:
  #22= #7 of #19;                         // InnerClass=class test4/MethodParamInnerClassTest$InnerClass of class test4/MethodParamInnerClassTest

It still contains MethodParameters, but there is no parameter names

MethodParameters:
      Name                           Flags
      <no name>                      final mandated

@wuwen5 wuwen5 force-pushed the java21-inner-class branch 2 times, most recently from d63c0ca to d6a1f2e Compare October 8, 2023 17:34
@wuwen5 wuwen5 changed the title fixes GitHub Issue 462 (Internal class issues in the Java 21) fixes GitHub Issue 462 (In Java21, the ConstPool API throws NPE for MethodParameters attributes without parameter names) Oct 10, 2023
@wuwen5 wuwen5 changed the title fixes GitHub Issue 462 (In Java21, the ConstPool API throws NPE for MethodParameters attributes without parameter names) fixes Issue 462 (In Java21, the ConstPool API throws NPE for MethodParameters attributes without parameter names) Oct 10, 2023
@wuwen5
Copy link
Contributor Author

wuwen5 commented Oct 10, 2023

@chibash

@liach
Copy link

liach commented Nov 3, 2023

This fix is not correct: you should check for 0-index at

return getConstPool().getUtf8Info(name(i));

to become:

int name = name(i);
return name == 0 ? null : getConstPool().getUtf8Info(name); 

and

ByteArray.write16bit(cp.addUtf8Info(names[i]), data, i * 4 + 1);

to become

String name = names[i];
ByteArray.write16bit(name == null ? 0 : cp.addUtf8Info(name), data, i * 4 + 1); 

instead.

@scottmarlow
Copy link
Contributor

@liach could you please approve the pull request if you think the change you requested was made.

@chibash are there any other committers on this project besides you and me? I propose that you pick from those that actively review others pull requests like @liach has done here.

Thanks,
Scott

Copy link

@liach liach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, though I'm not a project member.

@chibash chibash merged commit 1582943 into jboss-javassist:master Dec 4, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

In Java21, the ConstPool API throws NPE for MethodParameters attributes without parameter names
4 participants