Skip to content

IllegalStateException when creating TypePool.Default #119

@shot-mk

Description

@shot-mk

Hi,
I am trying to implement one of the example from your documentation, described in "Working with unloaded classes" part.
What i am doing is:

  • Creating default type pool like in the example :
    TypePool typePool = TypePool.Default.ofClassPath();
  • Then i am trying to redefine a class with ByteBuddy instance like this :
    new ByteBuddy().redefine(typePool.describe("my.class.Class").resolve(), ClassFileLocator.ForClassLoader.ofClassPath()) .method(ElementMatchers.named("toString")).intercept(FixedValue.value("intercepted")) .make() .load(ClassLoader.getSystemClassLoader(), ClassLoadingStrategy.Default.INJECTION);

The result is that I'm getting an IllegalStateException on method call typePool.describe("my.class.Class").resolve()

I've tried to investigate it and came to kind of a dead end: I found that TypePool.Default's describe() method is calling to the parent.describe(name) method. Furthermore the parent of TypePool.Default is TypePool.Empty which is hardcoded and can't be changed with the given API. The describe() method of TypePool.Empty returns object of type Resolution.Illegal with predifined resolve() method:

public TypeDescription resolve() {
    throw new IllegalStateException("Cannot resolve type description for " + name);
}

What am i missing? Maybe the example from you'r documentation http://bytebuddy.net/#/tutorial isn't uptodate? And the main question how can i achieve needed behavior?

I've also tried to to use TypePool.Default.ClassLoading or create my TypePooland even made it to work with a bit of hacking but I don't sure that any of them is a good practice because of the pretty well defined API that you are giving in this lib.

Thanks

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions