byte-buddy icon indicating copy to clipboard operation
byte-buddy copied to clipboard

Compilation error after adding lombok to classpath

Open omidp opened this issue 1 year ago • 1 comments

Hi,

I am not sure whether this is ByteBuddy or Lombok bug. I am trying to change javax.persistence to jakarta.persistence packages inside a legacy jar file with bytebuddy.

new ByteBuddy().redefine(clz, classFileLocator)
			.visit(new AsmVisitorWrapper() {
				@Override
				public int mergeWriter(int flags) {
					return 0;
				}

				@Override
				public int mergeReader(int flags) {
					return 0;
				}

				@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 ClassRemapper(classVisitor, new Remapper() {
						@Override
						public String map(String typeName) {
							for (Map.Entry<String, String> javaxAnnotation : javaxAnnotations.entrySet()) {
								String index = javaxAnnotation.getKey();
								if (typeToName(typeName).startsWith(index)) {
									//change javax.persistence.* to jakarta.persistence.*
									return javaxAnnotation.getValue() + typeToName(typeName).substring(index.length());
								}
							}
							return typeName;
						}
					});
				}
			}).make().getBytes();

It is successfully converting the packages, however, when I add lombok to my project classPath I am getting this compilation error.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project domain-system: Compilation failure
[ERROR] cannot access jakarta$persistence$MappedSuperclass
[ERROR]   class file for jakarta$persistence$MappedSuperclass not found

Is ByteBuddy lombok-friendly and good choice for solving this problem ?

PS: I have all required dependencies in the classpath.

omidp avatar Feb 15 '24 17:02 omidp

First, use AsmVisitorWrapper.AbstractBase or retain the modifiers. I do not think you want to reset them. The error happens during compilation in the annotation processor. This is before Byte Buddy is active, so I would not know how this is related to the library.

raphw avatar Feb 16 '24 13:02 raphw