diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/ClassFileVersion.java b/byte-buddy-dep/src/main/java/net/bytebuddy/ClassFileVersion.java index a3a09bf53c..90caaa854f 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/ClassFileVersion.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/ClassFileVersion.java @@ -402,7 +402,7 @@ public static ClassFileVersion ofClassFile(byte[] binaryRepresentation) { if (binaryRepresentation.length < 7) { throw new IllegalArgumentException("Supplied byte array is too short to be a class file with " + binaryRepresentation.length + " byte"); } - return ofMinorMajor(binaryRepresentation[6] << 8 | binaryRepresentation[7] & 0xFF); + return ofMinorMajor(binaryRepresentation[5] << 16 | binaryRepresentation[7] & 0xFF); } /** diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/ClassFileVersionTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/ClassFileVersionTest.java index c7075d8ac3..6d37526d6f 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/ClassFileVersionTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/ClassFileVersionTest.java @@ -77,6 +77,17 @@ public void testIllegalClassFile() throws Exception { ClassFileVersion.ofClassFile(new byte[0]); } + @Test + public void testClassFileVersion() { + for (int i = 1; i < ClassFileVersion.latest().getJavaVersion(); i++) { + byte major = (byte) (44 + i); + byte minor = (byte) (i == 1 ? 3 : 0); + + ClassFileVersion expected = ClassFileVersion.ofJavaVersion(i); + assertThat(ClassFileVersion.ofClassFile(new byte[]{0, 0, 0, 0, 0, minor, 0, major}), is(expected)); + } + } + private static class Foo { /* empty */ }