Skip to content

Commit

Permalink
Merge pull request #1510 from SylvainJuge/java1-version
Browse files Browse the repository at this point in the history
Fix reading bytecode version for java1
  • Loading branch information
raphw committed Aug 24, 2023
2 parents 76d90b1 + 9409ecc commit b7f94db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
}
Expand Down

0 comments on commit b7f94db

Please sign in to comment.