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

Question:Error when use maven plugin #1622

Open
twogoods opened this issue Apr 22, 2024 · 3 comments
Open

Question:Error when use maven plugin #1622

twogoods opened this issue Apr 22, 2024 · 3 comments
Assignees
Labels
Milestone

Comments

@twogoods
Copy link

I want to modify class when compile

        <plugins>
            <plugin>
                <groupId>net.bytebuddy</groupId>
                <artifactId>byte-buddy-maven-plugin</artifactId>
                <version>1.14.4</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>transform</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <transformations>
                        <transformation>
                            <groupId>xxx</groupId>
                            <artifactId>xxx</artifactId>
                            <version>${revision}</version>
                            <plugin>org.xxx.TestPlugin</plugin>
                        </transformation>
                    </transformations>
                </configuration>
            </plugin>

exception is

Caused by: java.lang.AbstractMethodError: org.xxx.Generator.wrap(Lnet/bytebuddy/description/type/TypeDescription;Lnet/bytebuddy/jar/asm/ClassVisitor;Lnet/bytebuddy/implementation/Implementation$Context;Lnet/bytebuddy/pool/TypePool;Lnet/bytebuddy/description/field/FieldList;Lnet/bytebuddy/description/method/MethodList;II)Lnet/bytebuddy/jar/asm/ClassVisitor;
	at net.bytebuddy.asm.AsmVisitorWrapper$Compound.wrap(AsmVisitorWrapper.java:746)
	at net.bytebuddy.dynamic.scaffold.TypeWriter$Default$ForInlining$WithFullProcessing$RedefinitionClassVisitor.visit(TypeWriter.java:5004)
	at net.bytebuddy.jar.asm.ClassReader.accept(ClassReader.java:569)
	at net.bytebuddy.jar.asm.ClassReader.accept(ClassReader.java:424)
	at net.bytebuddy.dynamic.scaffold.TypeWriter$Default$ForInlining.create(TypeWriter.java:4014)
	at net.bytebuddy.dynamic.scaffold.TypeWriter$Default.make(TypeWriter.java:2224)
	at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase$UsingTypeWriter.make(DynamicType.java:4057)
	at net.bytebuddy.build.Plugin$Engine$Default$Preprocessor$Resolved.call(Plugin.java:4893)
	at net.bytebuddy.build.Plugin$Engine$Default$Preprocessor$Resolved.call(Plugin.java:4850)
	at net.bytebuddy.build.Plugin$Engine$Dispatcher$ForSerialTransformation.accept(Plugin.java:3902)
	at net.bytebuddy.build.Plugin$Engine$Default.apply(Plugin.java:4697)
	at net.bytebuddy.build.maven.ByteBuddyMojo.apply(ByteBuddyMojo.java:468)
	... 23 more

code:

public class TestPlugin implements Plugin {
    @Override
    public DynamicType.Builder<?> apply(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassFileLocator classFileLocator) {
            Generator generator = new Generator();
            return builder.visit(generator);
    }
}

public class Generator implements AsmVisitorWrapper {

    @Override
    public ClassVisitor wrap(
            TypeDescription instrumentedType,
            ClassVisitor classVisitor,
            Implementation.Context implementationContext,
            TypePool typePool,
            FieldList<FieldDescription.InDefinedShape> fields,
            MethodList<?> methods,
            int writerFlags,
            int readerFlags) {
        return new GenerateMethods(classVisitor);
    }

class AsmVisitorWrapper load by same classloader, why get AbstractMethodError ?

@raphw
Copy link
Owner

raphw commented Apr 22, 2024

That is not clear to me from the example you provide.

Could you try to debug this by mvnDebug? You could intercept the method within the stack and see what the problem is.

@raphw raphw added the question label Apr 22, 2024
@raphw raphw self-assigned this Apr 22, 2024
@raphw raphw added this to the 1.14.14 milestone Apr 22, 2024
@twogoods
Copy link
Author

@raphw here is a sample bytebuddy-maven-plugin-test.
api contains bytebuddy build plugin, dependency has buddy and asm; demo build with byte-buddy-maven-plugin

mvn -X clean package will see error

@raphw
Copy link
Owner

raphw commented Apr 23, 2024

This is merely a consequence of an underlying: java.lang.ClassNotFoundException: org.objectweb.asm.ClassVisitor. Maven swallows this cause.

Do not use byte-buddy-dep but byte-buddy. Then use ClassVisitorFactory to bridge between different shading concepts of ASM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants