From 2aec9678b6623ff4d61cc776a0a069ac25d7b6f9 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Tue, 20 Aug 2024 11:26:27 +0200 Subject: [PATCH] Consistent use of factories. --- .../utility/dispatcher/JavaDispatcher.java | 5 ++-- .../asm/ClassVisitorFactoryOtherTest.java | 2 -- .../AbstractTypeDescriptionGenericTest.java | 3 ++- .../type/AbstractTypeDescriptionTest.java | 23 ++++++++++--------- .../AbstractDynamicTypeBuilderTest.java | 7 +++--- ...TypeWriterDeclarationPreservationTest.java | 7 +++--- .../scaffold/TypeWriterDefaultTest.java | 18 ++++++++------- .../AnnotationAppenderDefaultTest.java | 21 +++++++++-------- 8 files changed, 45 insertions(+), 41 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/utility/dispatcher/JavaDispatcher.java b/byte-buddy-dep/src/main/java/net/bytebuddy/utility/dispatcher/JavaDispatcher.java index 4b3642d0f16..2b61cc7128c 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/utility/dispatcher/JavaDispatcher.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/utility/dispatcher/JavaDispatcher.java @@ -17,6 +17,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import net.bytebuddy.ClassFileVersion; +import net.bytebuddy.asm.AsmVisitorWrapper; import net.bytebuddy.build.AccessControllerPlugin; import net.bytebuddy.build.HashCodeAndEqualsPlugin; import net.bytebuddy.description.method.MethodDescription; @@ -1234,7 +1235,7 @@ protected DynamicClassLoader(Class target) { */ @SuppressFBWarnings(value = {"REC_CATCH_EXCEPTION", "DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED"}, justification = "Expected internal invocation.") protected static Object proxy(Class proxy, Map dispatchers) { - ClassWriter classWriter = new ClassWriter(0); + ClassWriter classWriter = new ClassWriter(AsmVisitorWrapper.NO_FLAGS); classWriter.visit(ClassFileVersion.JAVA_V5.getMinorMajorVersion(), Opcodes.ACC_PUBLIC, Type.getInternalName(proxy) + "$Proxy", @@ -1310,7 +1311,7 @@ protected static Object proxy(Class proxy, Map dispatcher */ @SuppressFBWarnings(value = {"REC_CATCH_EXCEPTION", "DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED"}, justification = "Expected internal invocation.") protected static Invoker invoker() { - ClassWriter classWriter = new ClassWriter(0); + ClassWriter classWriter = new ClassWriter(AsmVisitorWrapper.NO_FLAGS); classWriter.visit(ClassFileVersion.JAVA_V5.getMinorMajorVersion(), Opcodes.ACC_PUBLIC, Type.getInternalName(Invoker.class) + "$Dispatcher", diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/asm/ClassVisitorFactoryOtherTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/asm/ClassVisitorFactoryOtherTest.java index b11fa6fcc21..6cddff09255 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/asm/ClassVisitorFactoryOtherTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/asm/ClassVisitorFactoryOtherTest.java @@ -1,11 +1,9 @@ package net.bytebuddy.asm; import net.bytebuddy.utility.OpenedClassReader; -import org.hamcrest.CoreMatchers; import org.junit.Test; import org.objectweb.asm.Attribute; import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.Opcodes; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/AbstractTypeDescriptionGenericTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/AbstractTypeDescriptionGenericTest.java index 94cff2dd291..1aae09e81b6 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/AbstractTypeDescriptionGenericTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/AbstractTypeDescriptionGenericTest.java @@ -1,5 +1,6 @@ package net.bytebuddy.description.type; +import net.bytebuddy.asm.AsmVisitorWrapper; import net.bytebuddy.description.TypeVariableSource; import net.bytebuddy.description.field.FieldDescription; import net.bytebuddy.description.method.MethodDescription; @@ -1996,7 +1997,7 @@ public static class GenericDisintegrator extends ClassVisitor { public static Field make() throws IOException, ClassNotFoundException, NoSuchFieldException { AsmClassReader classReader = AsmClassReader.Factory.Default.INSTANCE.make(ClassFileLocator.ForClassLoader.read(InconsistentGenerics.class)); AsmClassWriter classWriter = AsmClassWriter.Factory.Default.INSTANCE.make(ClassWriter.COMPUTE_MAXS, classReader); - classReader.accept(new GenericDisintegrator(classWriter.getVisitor()), 0); + classReader.accept(new GenericDisintegrator(classWriter.getVisitor()), AsmVisitorWrapper.NO_FLAGS); return new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, Collections.singletonMap(InconsistentGenerics.class.getName(), classWriter.getBinaryRepresentation()), ByteArrayClassLoader.PersistenceHandler.MANIFEST) diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/AbstractTypeDescriptionTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/AbstractTypeDescriptionTest.java index add1bb1bf56..583f284394e 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/AbstractTypeDescriptionTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/AbstractTypeDescriptionTest.java @@ -1,6 +1,7 @@ package net.bytebuddy.description.type; import net.bytebuddy.ByteBuddy; +import net.bytebuddy.asm.AsmVisitorWrapper; import net.bytebuddy.description.TypeVariableSource; import net.bytebuddy.description.annotation.AnnotationDescription; import net.bytebuddy.description.annotation.AnnotationList; @@ -779,13 +780,13 @@ public void testNestMatesSupported() throws Exception { @Test public void testNonEnclosedAnonymousType() throws Exception { - ClassWriter classWriter = new ClassWriter(0); - classWriter.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, "foo/Bar", null, "java/lang/Object", null); - classWriter.visitInnerClass("foo/Bar", null, null, Opcodes.ACC_PUBLIC); - classWriter.visitEnd(); + AsmClassWriter classWriter = AsmClassWriter.Factory.Default.INSTANCE.make(AsmVisitorWrapper.NO_FLAGS); + classWriter.getVisitor().visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, "foo/Bar", null, "java/lang/Object", null); + classWriter.getVisitor().visitInnerClass("foo/Bar", null, null, Opcodes.ACC_PUBLIC); + classWriter.getVisitor().visitEnd(); ClassLoader classLoader = new ByteArrayClassLoader(null, - Collections.singletonMap("foo.Bar", classWriter.toByteArray()), + Collections.singletonMap("foo.Bar", classWriter.getBinaryRepresentation()), ByteArrayClassLoader.PersistenceHandler.MANIFEST); Class type = classLoader.loadClass("foo.Bar"); @@ -949,8 +950,8 @@ public SignatureMalformer(ClassVisitor classVisitor) { public static Class malform(Class type) throws Exception { AsmClassReader classReader = AsmClassReader.Factory.Default.INSTANCE.make(ClassFileLocator.ForClassLoader.read(type)); - AsmClassWriter classWriter = AsmClassWriter.Factory.Default.INSTANCE.make(0, classReader); - classReader.accept(new SignatureMalformer(classWriter.getVisitor()), 0); + AsmClassWriter classWriter = AsmClassWriter.Factory.Default.INSTANCE.make(AsmVisitorWrapper.NO_FLAGS, classReader); + classReader.accept(new SignatureMalformer(classWriter.getVisitor()), AsmVisitorWrapper.NO_FLAGS); ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, Collections.singletonMap(type.getName(), classWriter.getBinaryRepresentation()), ByteArrayClassLoader.PersistenceHandler.MANIFEST); @@ -981,8 +982,8 @@ public TypeVariableMalformer(ClassVisitor classVisitor) { public static Class malform(Class type) throws Exception { AsmClassReader classReader = AsmClassReader.Factory.Default.INSTANCE.make(ClassFileLocator.ForClassLoader.read(type)); - AsmClassWriter classWriter = AsmClassWriter.Factory.Default.INSTANCE.make(0, classReader); - classReader.accept(new TypeVariableMalformer(classWriter.getVisitor()), 0); + AsmClassWriter classWriter = AsmClassWriter.Factory.Default.INSTANCE.make(AsmVisitorWrapper.NO_FLAGS, classReader); + classReader.accept(new TypeVariableMalformer(classWriter.getVisitor()), AsmVisitorWrapper.NO_FLAGS); ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, Collections.singletonMap(type.getName(), classWriter.getBinaryRepresentation()), ByteArrayClassLoader.PersistenceHandler.MANIFEST); @@ -1018,8 +1019,8 @@ public ParameterizedTypeLengthMalformer(ClassVisitor classVisitor) { public static Class malform(Class type) throws Exception { AsmClassReader classReader = AsmClassReader.Factory.Default.INSTANCE.make(ClassFileLocator.ForClassLoader.read(type)); - AsmClassWriter classWriter = AsmClassWriter.Factory.Default.INSTANCE.make(0, classReader); - classReader.accept(new ParameterizedTypeLengthMalformer(classWriter.getVisitor()), 0); + AsmClassWriter classWriter = AsmClassWriter.Factory.Default.INSTANCE.make(AsmVisitorWrapper.NO_FLAGS, classReader); + classReader.accept(new ParameterizedTypeLengthMalformer(classWriter.getVisitor()), AsmVisitorWrapper.NO_FLAGS); ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER, Collections.singletonMap(type.getName(), classWriter.getBinaryRepresentation()), ByteArrayClassLoader.PersistenceHandler.MANIFEST); diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/AbstractDynamicTypeBuilderTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/AbstractDynamicTypeBuilderTest.java index 114690ad408..aef2ad03808 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/AbstractDynamicTypeBuilderTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/AbstractDynamicTypeBuilderTest.java @@ -29,6 +29,7 @@ import net.bytebuddy.pool.TypePool; import net.bytebuddy.test.utility.CallTraceable; import net.bytebuddy.test.utility.JavaVersionRule; +import net.bytebuddy.utility.AsmClassWriter; import net.bytebuddy.utility.OpenedClassReader; import net.bytebuddy.utility.visitor.ContextClassVisitor; import org.hamcrest.CoreMatchers; @@ -1520,12 +1521,12 @@ public void testWrapClassVisitor() throws Exception { TypeDescription typeDescription = createPlain() .make() .getTypeDescription(); - ClassWriter classWriter = new ClassWriter(AsmVisitorWrapper.NO_FLAGS); + AsmClassWriter classWriter = AsmClassWriter.Factory.Default.INSTANCE.make(AsmVisitorWrapper.NO_FLAGS); ContextClassVisitor classVisitor = createPlain() .defineMethod(FOO, Object.class, Visibility.PUBLIC, Ownership.STATIC) .throwing(Exception.class) .intercept(new Implementation.Simple(new TextConstant(FOO), MethodReturn.REFERENCE)) - .wrap(classWriter); + .wrap(classWriter.getVisitor()); classVisitor.visit(ClassFileVersion.ofThisVm().getMinorMajorVersion(), typeDescription.getActualModifiers(true), typeDescription.getInternalName(), @@ -1536,7 +1537,7 @@ public void testWrapClassVisitor() throws Exception { assertThat(classVisitor.getAuxiliaryTypes().size(), is(0)); assertThat(classVisitor.getLoadedTypeInitializer().isAlive(), is(false)); Class type = new DynamicType.Default.Unloaded(typeDescription, - classWriter.toByteArray(), + classWriter.getBinaryRepresentation(), LoadedTypeInitializer.NoOp.INSTANCE, Collections.emptyList(), TypeResolutionStrategy.Passive.INSTANCE).load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded(); diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/scaffold/TypeWriterDeclarationPreservationTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/scaffold/TypeWriterDeclarationPreservationTest.java index 1357e961190..20939b7b500 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/scaffold/TypeWriterDeclarationPreservationTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/scaffold/TypeWriterDeclarationPreservationTest.java @@ -9,7 +9,6 @@ import net.bytebuddy.dynamic.ClassFileLocator; import net.bytebuddy.implementation.Implementation; import net.bytebuddy.pool.TypePool; -import net.bytebuddy.test.scope.EnclosingType; import net.bytebuddy.utility.AsmClassReader; import net.bytebuddy.utility.OpenedClassReader; import org.junit.Test; @@ -62,7 +61,7 @@ public TypeWriterDeclarationPreservationTest(Class type) { @Test public void testRedefinition() throws Exception { TypeModifierExtractor typeModifierExtractor = new TypeModifierExtractor(); - AsmClassReader.Factory.Default.INSTANCE.make(ClassFileLocator.ForClassLoader.read(type)).accept(typeModifierExtractor, 0); + AsmClassReader.Factory.Default.INSTANCE.make(ClassFileLocator.ForClassLoader.read(type)).accept(typeModifierExtractor, AsmVisitorWrapper.NO_FLAGS); new ByteBuddy() .redefine(type) .visit(new TypeValidator.Wrapper(typeModifierExtractor)) @@ -72,7 +71,7 @@ public void testRedefinition() throws Exception { @Test public void testRebasing() throws Exception { TypeModifierExtractor typeModifierExtractor = new TypeModifierExtractor(); - AsmClassReader.Factory.Default.INSTANCE.make(ClassFileLocator.ForClassLoader.read(type)).accept(typeModifierExtractor, 0); + AsmClassReader.Factory.Default.INSTANCE.make(ClassFileLocator.ForClassLoader.read(type)).accept(typeModifierExtractor, AsmVisitorWrapper.NO_FLAGS); new ByteBuddy() .rebase(type) .visit(new TypeValidator.Wrapper(typeModifierExtractor)) @@ -82,7 +81,7 @@ public void testRebasing() throws Exception { @Test public void testDecoration() throws Exception { TypeModifierExtractor typeModifierExtractor = new TypeModifierExtractor(); - AsmClassReader.Factory.Default.INSTANCE.make(ClassFileLocator.ForClassLoader.read(type)).accept(typeModifierExtractor, 0); + AsmClassReader.Factory.Default.INSTANCE.make(ClassFileLocator.ForClassLoader.read(type)).accept(typeModifierExtractor, AsmVisitorWrapper.NO_FLAGS); new ByteBuddy() .decorate(type) .visit(new TypeValidator.Wrapper(typeModifierExtractor)) diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/scaffold/TypeWriterDefaultTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/scaffold/TypeWriterDefaultTest.java index 4eb57e6f141..4390c553c96 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/scaffold/TypeWriterDefaultTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/dynamic/scaffold/TypeWriterDefaultTest.java @@ -18,6 +18,8 @@ import net.bytebuddy.implementation.SuperMethodCall; import net.bytebuddy.implementation.bytecode.ByteCodeAppender; import net.bytebuddy.test.utility.JavaVersionRule; +import net.bytebuddy.utility.AsmClassReader; +import net.bytebuddy.utility.AsmClassWriter; import net.bytebuddy.utility.JavaConstant; import net.bytebuddy.utility.OpenedClassReader; import org.junit.Rule; @@ -678,15 +680,15 @@ public void testPropertyDefinitionEmptyName() throws Exception { @Test public void testOldJavaClassFileDeprecation() { - ClassWriter classWriter = new ClassWriter(0); - classWriter.visit(Opcodes.V1_4, Opcodes.ACC_DEPRECATED | Opcodes.ACC_ABSTRACT, "foo/Bar", null, "java/lang/Object", null); - classWriter.visitField(Opcodes.ACC_DEPRECATED, "qux", "Ljava/lang/Object;", null, null).visitEnd(); - classWriter.visitMethod(Opcodes.ACC_DEPRECATED | Opcodes.ACC_ABSTRACT, "baz", "()V", null, null).visitEnd(); - classWriter.visitEnd(); + AsmClassWriter classWriter = AsmClassWriter.Factory.Default.INSTANCE.make(AsmVisitorWrapper.NO_FLAGS); + classWriter.getVisitor().visit(Opcodes.V1_4, Opcodes.ACC_DEPRECATED | Opcodes.ACC_ABSTRACT, "foo/Bar", null, "java/lang/Object", null); + classWriter.getVisitor().visitField(Opcodes.ACC_DEPRECATED, "qux", "Ljava/lang/Object;", null, null).visitEnd(); + classWriter.getVisitor().visitMethod(Opcodes.ACC_DEPRECATED | Opcodes.ACC_ABSTRACT, "baz", "()V", null, null).visitEnd(); + classWriter.getVisitor().visitEnd(); TypeDescription typeDescription = new TypeDescription.Latent("foo.Bar", 0, TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(Object.class)); Class type = ByteArrayClassLoader.load(ClassLoadingStrategy.BOOTSTRAP_LOADER, - Collections.singletonMap(typeDescription, classWriter.toByteArray()), + Collections.singletonMap(typeDescription, classWriter.getBinaryRepresentation()), ClassLoadingStrategy.NO_PROTECTION_DOMAIN, ByteArrayClassLoader.PersistenceHandler.MANIFEST, PackageDefinitionStrategy.Trivial.INSTANCE, @@ -700,7 +702,7 @@ public void testOldJavaClassFileDeprecation() { .make() .getBytes(); - ClassReader classReader = new ClassReader(binaryRepresentation); + AsmClassReader classReader = AsmClassReader.Factory.Default.INSTANCE.make(binaryRepresentation); classReader.accept(new ClassVisitor(OpenedClassReader.ASM_API) { @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { @@ -725,7 +727,7 @@ public MethodVisitor visitMethod(int access, String name, String descriptor, Str } return super.visitMethod(access, name, descriptor, signature, exceptions); } - }, 0); + }, AsmVisitorWrapper.NO_FLAGS); } @Retention(RetentionPolicy.RUNTIME) diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/implementation/attribute/AnnotationAppenderDefaultTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/implementation/attribute/AnnotationAppenderDefaultTest.java index 81e893b6f1c..d3fef737240 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/implementation/attribute/AnnotationAppenderDefaultTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/implementation/attribute/AnnotationAppenderDefaultTest.java @@ -7,6 +7,7 @@ import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.dynamic.loading.ByteArrayClassLoader; import net.bytebuddy.test.utility.JavaVersionRule; +import net.bytebuddy.utility.AsmClassWriter; import org.hamcrest.CoreMatchers; import org.junit.Before; import org.junit.Rule; @@ -156,19 +157,19 @@ public void testMultipleTypeArgumentAnnotation() throws Exception { private Class makeTypeWithAnnotation(Annotation annotation) throws Exception { when(valueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true); - ClassWriter classWriter = new ClassWriter(AsmVisitorWrapper.NO_FLAGS); - classWriter.visit(ClassFileVersion.ofThisVm().getMinorMajorVersion(), + AsmClassWriter classWriter = AsmClassWriter.Factory.Default.INSTANCE.make(AsmVisitorWrapper.NO_FLAGS); + classWriter.getVisitor().visit(ClassFileVersion.ofThisVm().getMinorMajorVersion(), Opcodes.ACC_PUBLIC, BAR.replace('.', '/'), null, Type.getInternalName(Object.class), null); - AnnotationVisitor annotationVisitor = classWriter.visitAnnotation(Type.getDescriptor(annotation.annotationType()), true); + AnnotationVisitor annotationVisitor = classWriter.getVisitor().visitAnnotation(Type.getDescriptor(annotation.annotationType()), true); when(target.visit(any(String.class), anyBoolean())).thenReturn(annotationVisitor); AnnotationDescription annotationDescription = AnnotationDescription.ForLoadedAnnotation.of(annotation); annotationAppender.append(annotationDescription, valueFilter); - classWriter.visitEnd(); - Class bar = new ByteArrayClassLoader(getClass().getClassLoader(), Collections.singletonMap(BAR, classWriter.toByteArray())).loadClass(BAR); + classWriter.getVisitor().visitEnd(); + Class bar = new ByteArrayClassLoader(getClass().getClassLoader(), Collections.singletonMap(BAR, classWriter.getBinaryRepresentation())).loadClass(BAR); assertThat(bar.getName(), is(BAR)); assertThat(bar.getSuperclass(), CoreMatchers.>is(Object.class)); return bar; @@ -176,22 +177,22 @@ private Class makeTypeWithAnnotation(Annotation annotation) throws Exception private Class makeTypeWithSuperClassAnnotation(Annotation annotation) throws Exception { when(valueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true); - ClassWriter classWriter = new ClassWriter(AsmVisitorWrapper.NO_FLAGS); - classWriter.visit(ClassFileVersion.ofThisVm().getMinorMajorVersion(), + AsmClassWriter classWriter = AsmClassWriter.Factory.Default.INSTANCE.make(AsmVisitorWrapper.NO_FLAGS); + classWriter.getVisitor().visit(ClassFileVersion.ofThisVm().getMinorMajorVersion(), Opcodes.ACC_PUBLIC, BAR.replace('.', '/'), null, Type.getInternalName(Object.class), null); - AnnotationVisitor annotationVisitor = classWriter.visitTypeAnnotation(TypeReference.newSuperTypeReference(-1).getValue(), + AnnotationVisitor annotationVisitor = classWriter.getVisitor().visitTypeAnnotation(TypeReference.newSuperTypeReference(-1).getValue(), null, Type.getDescriptor(annotation.annotationType()), true); when(target.visit(any(String.class), anyBoolean())).thenReturn(annotationVisitor); AnnotationDescription annotationDescription = AnnotationDescription.ForLoadedAnnotation.of(annotation); annotationAppender.append(annotationDescription, valueFilter); - classWriter.visitEnd(); - Class bar = new ByteArrayClassLoader(getClass().getClassLoader(), Collections.singletonMap(BAR, classWriter.toByteArray())).loadClass(BAR); + classWriter.getVisitor().visitEnd(); + Class bar = new ByteArrayClassLoader(getClass().getClassLoader(), Collections.singletonMap(BAR, classWriter.getBinaryRepresentation())).loadClass(BAR); assertThat(bar.getName(), is(BAR)); assertThat(bar.getSuperclass(), CoreMatchers.>is(Object.class)); return bar;