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

Lower requirement for an extra type in constructor to Java 7- #390

Merged
merged 1 commit into from May 10, 2022

Conversation

derklaro
Copy link
Contributor

@derklaro derklaro commented Sep 7, 2021

Evening,
first of all thanks for the great project!

This pull request lowers the requirement for an extra javaassist.runtime.Inner type in the target constructor when calling a private constructor from an inner class. This check was introduced in #253 and makes no sense considering that the constructor invocation still works on older jvms like 8. (tested against jvm versions HotSpot 1.8.0_241-b07, HotSpot 11.0.6+8-LTS and HotSpot 18-ea+12-613).

The test setup was as follows:

public class Test {
  private static final class Test1234 {

    private final String a;

    private Test1234(String a) {
      this.a = a;
    }
  }
}

The generated class looked like this before the change:

public class Test$Test1234$Invoker_10631572689300 implements InstanceMaker {
  private final Type[] type;
  AtomicReference instance = new AtomicReference();

  Test$Test1234$Invoker_10631572689300(Type[] var1) {
    this.type = var1;
  }

  public Object getInstance(InjectionContext var1) {
    if (this.instance.get() == null) {
      this.instance.set(new Test1234(/*calls to get the required string for the class*/, (Inner)null));
    }

    return this.instance.get();
  }
}

And like this after the change:

public class Test$Test1234$Invoker_16422617283600 implements InstanceMaker {
  private final Type[] type;
  AtomicReference instance = new AtomicReference();

  Test$Test1234$Invoker_16422617283600(Type[] var1) {
    this.type = var1;
  }

  public Object getInstance(InjectionContext var1) {
    if (this.instance.get() == null) {
      this.instance.set(new Test1234(/*calls to get the required string for the class*/));
    }

    return this.instance.get();
  }
}

The code after the change works as expected allowing me to call the private Constructor from the inner class while the code before the change obviously doesn't as there is no constructor with the String, Inner signature

I was unable to test this on older jvm versions than 8 so i lowered the check to 8.

@chibash chibash merged commit b846257 into jboss-javassist:master May 10, 2022
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.

None yet

2 participants