diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/TypeWriter.java b/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/TypeWriter.java index b189d5b7bf5..aeebe9e1d9b 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/TypeWriter.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/TypeWriter.java @@ -3326,7 +3326,7 @@ protected ForClassFileVersion(ClassFileVersion classFileVersion) { public void assertType(int modifiers, boolean definesInterfaces, boolean isGeneric) { if ((modifiers & Opcodes.ACC_ANNOTATION) != 0 && !classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)) { throw new IllegalStateException("Cannot define annotation type for class file version " + classFileVersion); - } else if (isGeneric && !classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)) { + } else if (isGeneric && !classFileVersion.isAtLeast(ClassFileVersion.JAVA_V4)) { // JSR14 allows for generic 1.4 classes. throw new IllegalStateException("Cannot define a generic type for class file version " + classFileVersion); } } @@ -3335,7 +3335,7 @@ public void assertType(int modifiers, boolean definesInterfaces, boolean isGener * {@inheritDoc} */ public void assertField(String name, boolean isPublic, boolean isStatic, boolean isFinal, boolean isGeneric) { - if (isGeneric && !classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)) { + if (isGeneric && !classFileVersion.isAtLeast(ClassFileVersion.JAVA_V4)) { // JSR14 allows for generic 1.4 classes. throw new IllegalStateException("Cannot define generic field '" + name + "' for class file version " + classFileVersion); } } @@ -3352,7 +3352,7 @@ public void assertMethod(String name, boolean isConstructor, boolean isDefaultValueIncompatible, boolean isGeneric) { - if (isGeneric && !classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)) { + if (isGeneric && !classFileVersion.isAtLeast(ClassFileVersion.JAVA_V4)) { // JSR14 allows for generic 1.4 classes. throw new IllegalStateException("Cannot define generic method '" + name + "' for class file version " + classFileVersion); } else if (!isVirtual && isAbstract) { throw new IllegalStateException("Cannot define static or non-virtual method '" + name + "' to be abstract"); diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/implementation/InvocationHandlerAdapter.java b/byte-buddy-dep/src/main/java/net/bytebuddy/implementation/InvocationHandlerAdapter.java index 15ed37decac..37e119acd1d 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/implementation/InvocationHandlerAdapter.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/implementation/InvocationHandlerAdapter.java @@ -31,7 +31,6 @@ import net.bytebuddy.implementation.bytecode.member.MethodInvocation; import net.bytebuddy.implementation.bytecode.member.MethodReturn; import net.bytebuddy.implementation.bytecode.member.MethodVariableAccess; -import net.bytebuddy.matcher.ElementMatchers; import net.bytebuddy.utility.RandomString; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; diff --git a/byte-buddy-dep/src/precompiled/java/net/bytebuddy/test/precompiled/Jsr14Sample.java b/byte-buddy-dep/src/precompiled/java/net/bytebuddy/test/precompiled/Jsr14Sample.java new file mode 100644 index 00000000000..b72e4e1dfdb --- /dev/null +++ b/byte-buddy-dep/src/precompiled/java/net/bytebuddy/test/precompiled/Jsr14Sample.java @@ -0,0 +1,23 @@ +/* + * Copyright 2014 - 2020 Rafael Winterhalter + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.bytebuddy.test.precompiled; + +public class Jsr14Sample { + + public Jsr14Sample field; + + public Jsr14Sample method() { return null; } +} diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/ByteBuddyTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/ByteBuddyTest.java index dc949df6cce..e12f9f72fa5 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/ByteBuddyTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/ByteBuddyTest.java @@ -9,7 +9,6 @@ import net.bytebuddy.implementation.MethodDelegation; import net.bytebuddy.implementation.StubMethod; import net.bytebuddy.matcher.ElementMatchers; -import net.bytebuddy.test.utility.DebuggingWrapper; import org.junit.Ignore; import org.junit.Test; @@ -20,7 +19,6 @@ import java.util.Collections; import static net.bytebuddy.matcher.ElementMatchers.isTypeInitializer; -import static net.bytebuddy.matcher.ElementMatchers.returns; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; @@ -170,6 +168,17 @@ public void testClassWithManyMethods() throws Exception { assertThat(subclass.getDeclaredMethods().length, is(1000)); } + @Test + public void testClassCompiledToJsr14() throws Exception { + assertThat(new ByteBuddy() + .redefine(Class.forName("net.bytebuddy.test.precompiled.Jsr14Sample")) + .make() + .load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER) + .getLoaded() + .getConstructor() + .newInstance(), notNullValue()); + } + public static class Recorder { public int counter; diff --git a/byte-buddy-dep/src/test/resources/net/bytebuddy/test/precompiled/Jsr14Sample.class b/byte-buddy-dep/src/test/resources/net/bytebuddy/test/precompiled/Jsr14Sample.class new file mode 100644 index 00000000000..d75a2d4865b Binary files /dev/null and b/byte-buddy-dep/src/test/resources/net/bytebuddy/test/precompiled/Jsr14Sample.class differ