Skip to content

Commit

Permalink
Update ASM.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jun 28, 2021
1 parent 07411f0 commit c1f9548
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
11 changes: 10 additions & 1 deletion byte-buddy-dep/src/main/java/net/bytebuddy/ClassFileVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public class ClassFileVersion implements Comparable<ClassFileVersion> {
/**
* The class file version of Java 18.
*/
public static final ClassFileVersion JAVA_V18 = new ClassFileVersion(Opcodes.V17 + 1);
public static final ClassFileVersion JAVA_V18 = new ClassFileVersion(Opcodes.V18);

/**
* A version locator for the executing JVM.
Expand Down Expand Up @@ -286,6 +286,15 @@ public static ClassFileVersion ofJavaVersion(int javaVersion) {
}
}

/**
* Returns the latest officially supported Java version when experimental support is not enabled.
*
* @return The latest officially supported Java version.
*/
public static ClassFileVersion latest() {
return ClassFileVersion.JAVA_V18;
}

/**
* Finds the highest class file version that is compatible to the current JVM version. Prior to Java 9, this is achieved
* by parsing the {@code java.version} property which is provided by {@link java.lang.System#getProperty(String)}. If the system
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ private static <T> T doPrivileged(PrivilegedAction<T> action) {
*/
public static ClassReader of(byte[] binaryRepresentation) {
if (EXPERIMENTAL) {
ClassFileVersion classFileVersion = ClassFileVersion.ofClassFile(binaryRepresentation);
if (classFileVersion.isGreaterThan(ClassFileVersion.JAVA_V14)) {
binaryRepresentation[6] = (byte) (ClassFileVersion.JAVA_V14.getMajorVersion() >>> 8);
binaryRepresentation[7] = (byte) ClassFileVersion.JAVA_V14.getMajorVersion();
ClassFileVersion classFileVersion = ClassFileVersion.ofClassFile(binaryRepresentation), latest = ClassFileVersion.latest();
if (classFileVersion.isGreaterThan(latest)) {
binaryRepresentation[6] = (byte) (latest.getMajorVersion() >>> 8);
binaryRepresentation[7] = (byte) latest.getMajorVersion();
ClassReader classReader = new ClassReader(binaryRepresentation);
binaryRepresentation[6] = (byte) (classFileVersion.getMajorVersion() >>> 8);
binaryRepresentation[7] = (byte) classFileVersion.getMajorVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ public void testClassFile() throws Exception {
assertThat(ClassFileVersion.of(Object.class).getMinorMajorVersion(), not(0));
}

@Test
public void testLatestVersion() throws Exception {
Pattern pattern = Pattern.compile("JAVA_V[0-9]+");
ClassFileVersion latest = null;
for (Field field : ClassFileVersion.class.getFields()) {
if (pattern.matcher(field.getName()).matches()) {
ClassFileVersion classFileVersion = (ClassFileVersion) field.get(null);
if (latest == null || classFileVersion.isGreaterThan(latest)) {
latest = classFileVersion;
}
}
}
assertThat(ClassFileVersion.latest(), is(latest));
}

@Test(expected = IllegalArgumentException.class)
public void testIllegalClassFile() throws Exception {
ClassFileVersion.ofClassFile(new byte[0]);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<pitest.target>net.bytebuddy</pitest.target>
<asm.url>https://asm.ow2.io</asm.url>
<nexus.url>https://oss.sonatype.org</nexus.url>
<version.asm>9.1</version.asm>
<version.asm>9.2</version.asm>
<jna.version>5.8.0</jna.version>
<version.junit>4.13.2</version.junit>
<version.mockito>2.23.0</version.mockito>
Expand Down

0 comments on commit c1f9548

Please sign in to comment.