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

java.lang.NoSuchMethodError after the inner class which has access to the private constructor of the host class is instrumented #252

Closed
sam-ma opened this issue Mar 20, 2019 · 0 comments

Comments

@sam-ma
Copy link
Contributor

sam-ma commented Mar 20, 2019

Consider a class like this, where the inner class has access to the private constructor of the host class.

package test5;

public class NestHost3 {
  private NestHost3(Builder builder) {}
  public static Builder builder() {
    return new Builder();
  }
  public static final class Builder {
    public Builder() {}
    public NestHost3 build() {
      return new NestHost3(this);
    }
  }
}

Then the inner class is instrumented WITHOUT any modification.

public static void main(String[] args) throws Exception {
    ClassPool pool = ClassPool.getDefault();
    CtClass cc = pool.get("test5.NestHost3$Builder");
    cc.instrument(new ExprEditor() {
        public void edit(NewExpr e) throws CannotCompileException {
            String code = "$_ = $proceed($$);";
            e.replace(code);
        }
    });
    cc.writeFile();
}

A call like Section.builder().build(); will throw the following exception.

java.lang.NoSuchMethodError: test5.NestHost3.<init>(Ltest5/NestHost3$Builder;Ljavassist/runtime/Inner;)V

I find this only happen when using JDK11. Probably it's related to JEP181.

chibash added a commit that referenced this issue Apr 15, 2019
Fix #252 make instrumentation works on JDK11 for the inner class which has access to the private constructor of the host class
odl-github pushed a commit to opendaylight/odlparent that referenced this issue Oct 10, 2019
3.25 fixes:
- jboss-javassist/javassist#72
- jboss-javassist/javassist#241
- jboss-javassist/javassist#242
- jboss-javassist/javassist#246
- jboss-javassist/javassist#252
3.26 fixes:
- jboss-javassist/javassist#265
- jboss-javassist/javassist#270
- jboss-javassist/javassist#271
- jboss-javassist/javassist#275

Of these #270 is most important, as it fixes an issue we've seen
with powermock downstream.

Change-Id: Ib4d75d6411e71438436249a8eb9313ccf4411ca2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
odl-github pushed a commit to opendaylight/odlparent that referenced this issue Oct 17, 2019
3.25 fixes:
- jboss-javassist/javassist#72
- jboss-javassist/javassist#241
- jboss-javassist/javassist#242
- jboss-javassist/javassist#246
- jboss-javassist/javassist#252
3.26 fixes:
- jboss-javassist/javassist#265
- jboss-javassist/javassist#270
- jboss-javassist/javassist#271
- jboss-javassist/javassist#275

Of these #270 is most important, as it fixes an issue we've seen
with powermock downstream.

Change-Id: Ib4d75d6411e71438436249a8eb9313ccf4411ca2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 6a404f1)
odl-github pushed a commit to opendaylight/odlparent that referenced this issue Oct 17, 2019
3.25 fixes:
- jboss-javassist/javassist#72
- jboss-javassist/javassist#241
- jboss-javassist/javassist#242
- jboss-javassist/javassist#246
- jboss-javassist/javassist#252
3.26 fixes:
- jboss-javassist/javassist#265
- jboss-javassist/javassist#270
- jboss-javassist/javassist#271
- jboss-javassist/javassist#275

Of these #270 is most important, as it fixes an issue we've seen
with powermock downstream.

Change-Id: Ib4d75d6411e71438436249a8eb9313ccf4411ca2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 6a404f1)
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

No branches or pull requests

1 participant