Skip to content

Commit

Permalink
Update maximum supported Java class version to 67.65535 (Java 23)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjameshamilton committed Aug 22, 2024
1 parent a00d7f1 commit 7877db6
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ public class JavaVersionConstants {
public static final String CLASS_VERSION_20 = "20";
public static final String CLASS_VERSION_21 = "21";
public static final String CLASS_VERSION_22 = "22";
public static final String CLASS_VERSION_23 = "23";
}
6 changes: 5 additions & 1 deletion base/src/main/java/proguard/classfile/VersionConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public class VersionConstants {
public static final int CLASS_VERSION_21_MINOR = 0;
public static final int CLASS_VERSION_22_MAJOR = 66;
public static final int CLASS_VERSION_22_MINOR = 0;
public static final int CLASS_VERSION_23_MAJOR = 67;
public static final int CLASS_VERSION_23_MINOR = 0;
public static final int PREVIEW_VERSION_MINOR = 65535;

public static final int CLASS_VERSION_1_0 =
Expand Down Expand Up @@ -115,7 +117,9 @@ public class VersionConstants {
(CLASS_VERSION_21_MAJOR << 16) | CLASS_VERSION_21_MINOR;
public static final int CLASS_VERSION_22 =
(CLASS_VERSION_22_MAJOR << 16) | CLASS_VERSION_22_MINOR;
public static final int CLASS_VERSION_23 =
(CLASS_VERSION_23_MAJOR << 16) | CLASS_VERSION_23_MINOR;

public static final int MAX_SUPPORTED_VERSION =
(CLASS_VERSION_22_MAJOR << 16) | PREVIEW_VERSION_MINOR;
(CLASS_VERSION_23_MAJOR << 16) | PREVIEW_VERSION_MINOR;
}
149 changes: 57 additions & 92 deletions base/src/main/java/proguard/classfile/util/ClassUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,98 +94,61 @@ public static int internalMinorClassVersion(int internalClassVersion) {
* @return the internal class version number.
*/
public static int internalClassVersion(String externalClassVersion) {
return externalClassVersion.equals(JavaVersionConstants.CLASS_VERSION_1_0)
|| externalClassVersion.equals(JavaVersionConstants.CLASS_VERSION_1_1)
? VersionConstants.CLASS_VERSION_1_0
: externalClassVersion.equals(JavaVersionConstants.CLASS_VERSION_1_2)
? VersionConstants.CLASS_VERSION_1_2
: externalClassVersion.equals(JavaVersionConstants.CLASS_VERSION_1_3)
? VersionConstants.CLASS_VERSION_1_3
: externalClassVersion.equals(JavaVersionConstants.CLASS_VERSION_1_4)
? VersionConstants.CLASS_VERSION_1_4
: externalClassVersion.equals(JavaVersionConstants.CLASS_VERSION_1_5_ALIAS)
|| externalClassVersion.equals(JavaVersionConstants.CLASS_VERSION_1_5)
? VersionConstants.CLASS_VERSION_1_5
: externalClassVersion.equals(JavaVersionConstants.CLASS_VERSION_1_6_ALIAS)
|| externalClassVersion.equals(
JavaVersionConstants.CLASS_VERSION_1_6)
? VersionConstants.CLASS_VERSION_1_6
: externalClassVersion.equals(
JavaVersionConstants.CLASS_VERSION_1_7_ALIAS)
|| externalClassVersion.equals(
JavaVersionConstants.CLASS_VERSION_1_7)
? VersionConstants.CLASS_VERSION_1_7
: externalClassVersion.equals(
JavaVersionConstants.CLASS_VERSION_1_8_ALIAS)
|| externalClassVersion.equals(
JavaVersionConstants.CLASS_VERSION_1_8)
? VersionConstants.CLASS_VERSION_1_8
: externalClassVersion.equals(
JavaVersionConstants.CLASS_VERSION_1_9_ALIAS)
|| externalClassVersion.equals(
JavaVersionConstants.CLASS_VERSION_1_9)
? VersionConstants.CLASS_VERSION_1_9
: externalClassVersion.equals(
JavaVersionConstants.CLASS_VERSION_10)
? VersionConstants.CLASS_VERSION_10
: externalClassVersion.equals(
JavaVersionConstants.CLASS_VERSION_11)
? VersionConstants.CLASS_VERSION_11
: externalClassVersion.equals(
JavaVersionConstants.CLASS_VERSION_12)
? VersionConstants.CLASS_VERSION_12
: externalClassVersion.equals(
JavaVersionConstants.CLASS_VERSION_13)
? VersionConstants.CLASS_VERSION_13
: externalClassVersion.equals(
JavaVersionConstants
.CLASS_VERSION_14)
? VersionConstants.CLASS_VERSION_14
: externalClassVersion.equals(
JavaVersionConstants
.CLASS_VERSION_15)
? VersionConstants.CLASS_VERSION_15
: externalClassVersion.equals(
JavaVersionConstants
.CLASS_VERSION_16)
? VersionConstants
.CLASS_VERSION_16
: externalClassVersion.equals(
JavaVersionConstants
.CLASS_VERSION_17)
? VersionConstants
.CLASS_VERSION_17
: externalClassVersion
.equals(
JavaVersionConstants
.CLASS_VERSION_18)
? VersionConstants
.CLASS_VERSION_18
: externalClassVersion
.equals(
JavaVersionConstants
.CLASS_VERSION_19)
? VersionConstants
.CLASS_VERSION_19
: externalClassVersion
.equals(
JavaVersionConstants
.CLASS_VERSION_20)
? VersionConstants
.CLASS_VERSION_20
: externalClassVersion
.equals(
JavaVersionConstants
.CLASS_VERSION_21)
? VersionConstants
.CLASS_VERSION_21
: externalClassVersion
.equals(
JavaVersionConstants
.CLASS_VERSION_22)
? VersionConstants
.CLASS_VERSION_22
: 0;
switch (externalClassVersion) {
case JavaVersionConstants.CLASS_VERSION_1_0:
case JavaVersionConstants.CLASS_VERSION_1_1:
return VersionConstants.CLASS_VERSION_1_0;
case JavaVersionConstants.CLASS_VERSION_1_2:
return VersionConstants.CLASS_VERSION_1_2;
case JavaVersionConstants.CLASS_VERSION_1_3:
return VersionConstants.CLASS_VERSION_1_3;
case JavaVersionConstants.CLASS_VERSION_1_4:
return VersionConstants.CLASS_VERSION_1_4;
case JavaVersionConstants.CLASS_VERSION_1_5_ALIAS:
case JavaVersionConstants.CLASS_VERSION_1_5:
return VersionConstants.CLASS_VERSION_1_5;
case JavaVersionConstants.CLASS_VERSION_1_6_ALIAS:
case JavaVersionConstants.CLASS_VERSION_1_6:
return VersionConstants.CLASS_VERSION_1_6;
case JavaVersionConstants.CLASS_VERSION_1_7_ALIAS:
case JavaVersionConstants.CLASS_VERSION_1_7:
return VersionConstants.CLASS_VERSION_1_7;
case JavaVersionConstants.CLASS_VERSION_1_8_ALIAS:
case JavaVersionConstants.CLASS_VERSION_1_8:
return VersionConstants.CLASS_VERSION_1_8;
case JavaVersionConstants.CLASS_VERSION_1_9_ALIAS:
case JavaVersionConstants.CLASS_VERSION_1_9:
return VersionConstants.CLASS_VERSION_1_9;
case JavaVersionConstants.CLASS_VERSION_10:
return VersionConstants.CLASS_VERSION_10;
case JavaVersionConstants.CLASS_VERSION_11:
return VersionConstants.CLASS_VERSION_11;
case JavaVersionConstants.CLASS_VERSION_12:
return VersionConstants.CLASS_VERSION_12;
case JavaVersionConstants.CLASS_VERSION_13:
return VersionConstants.CLASS_VERSION_13;
case JavaVersionConstants.CLASS_VERSION_14:
return VersionConstants.CLASS_VERSION_14;
case JavaVersionConstants.CLASS_VERSION_15:
return VersionConstants.CLASS_VERSION_15;
case JavaVersionConstants.CLASS_VERSION_16:
return VersionConstants.CLASS_VERSION_16;
case JavaVersionConstants.CLASS_VERSION_17:
return VersionConstants.CLASS_VERSION_17;
case JavaVersionConstants.CLASS_VERSION_18:
return VersionConstants.CLASS_VERSION_18;
case JavaVersionConstants.CLASS_VERSION_19:
return VersionConstants.CLASS_VERSION_19;
case JavaVersionConstants.CLASS_VERSION_20:
return VersionConstants.CLASS_VERSION_20;
case JavaVersionConstants.CLASS_VERSION_21:
return VersionConstants.CLASS_VERSION_21;
case JavaVersionConstants.CLASS_VERSION_22:
return VersionConstants.CLASS_VERSION_22;
case JavaVersionConstants.CLASS_VERSION_23:
return VersionConstants.CLASS_VERSION_23;
}
return 0;
}

/**
Expand Down Expand Up @@ -240,6 +203,8 @@ public static String externalClassVersion(int internalClassVersion) {
return JavaVersionConstants.CLASS_VERSION_21;
case VersionConstants.CLASS_VERSION_22:
return JavaVersionConstants.CLASS_VERSION_22;
case VersionConstants.CLASS_VERSION_23:
return JavaVersionConstants.CLASS_VERSION_23;
default:
return null;
}
Expand Down
19 changes: 19 additions & 0 deletions base/src/test/kotlin/proguard/classfile/util/ClassUtilTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ class ClassUtilTest : BehaviorSpec({
}
}

Given("Class file version 23") {
val version = 67 shl 16
Then("The external version should be 23") {
externalClassVersion(version) shouldBe "23"
}

And("Given a class file with version 23") {
val programClass = ClassBuilder(
version,
PUBLIC,
"Test",
"java/lang/Object",
).programClass
Then("The internal version should be 23") {
programClass.u4version shouldBe internalClassVersion("23")
}
}
}

Given("A valid magic number") {
Then("No exception should be thrown") {
shouldNotThrowAny {
Expand Down
4 changes: 4 additions & 0 deletions docs/md/releasenotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Version 9.1.6

### Java support

- Update maximum supported Java class version to 67.65535 (Java 23).

### API changes

- Make `CallGraph` reconstruction/traversal methods generic in that they now take a `Set<MethodSignature>` to determine when to stop exploration
Expand Down

0 comments on commit 7877db6

Please sign in to comment.