Skip to content

Commit 4d14daa

Browse files
authored
Merge pull request #53 from MinimallyCorrect/jdk16
Support JDK 16
2 parents ef0d2a5 + c9d6198 commit 4d14daa

File tree

7 files changed

+45
-72
lines changed

7 files changed

+45
-72
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
runs-on: ubuntu-latest
2121
strategy:
2222
matrix:
23-
jdk: [11, 15]
23+
jdk: [11, 15, 16]
2424
steps:
2525
- uses: actions/checkout@v2
2626
- uses: actions/cache@v2.1.4

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
id("java")
44
id("java-library")
55
id("maven-publish")
6-
id("dev.minco.gradle.defaults-plugin") version "0.2.8"
6+
id("dev.minco.gradle.defaults-plugin") version "0.2.26"
77
id("org.shipkit.shipkit-auto-version") version "1.1.1"
88
id("org.shipkit.shipkit-changelog") version "1.1.4"
99
id("org.shipkit.shipkit-github-release") version "1.1.4"

gradle.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# The exports are needed due to https://github.com/diffplug/spotless/issues/834
2+
org.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
3+
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
4+
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
5+
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
6+
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED

src/main/java/dev/minco/javatransformer/internal/util/DefineClass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import lombok.SneakyThrows;
1111

1212
public final class DefineClass {
13-
private static final MethodHandles.Lookup $L = UnsafeAccess.IMPL_LOOKUP;
13+
private static final MethodHandles.Lookup $L = LookupAccess.privateLookupFor(ClassLoader.class);
1414
private static final ProtectionDomain PROTECTION_DOMAIN = AccessController.doPrivileged((PrivilegedAction<ProtectionDomain>) DefineClass.class::getProtectionDomain);
1515
private static final MethodHandle defineClassHandle = getDefineClassHandle();
1616

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package dev.minco.javatransformer.internal.util;
2+
3+
import java.lang.invoke.MethodHandles;
4+
5+
import lombok.SneakyThrows;
6+
import lombok.val;
7+
8+
public class LookupAccess {
9+
private static final MethodHandles.Lookup IMPL_LOOKUP;
10+
11+
@SneakyThrows
12+
public static MethodHandles.Lookup privateLookupFor(Class<?> clazz) {
13+
if (IMPL_LOOKUP != null) {
14+
return IMPL_LOOKUP;
15+
}
16+
17+
MethodHandles.Lookup lookup = MethodHandles.lookup();
18+
19+
Object privateLookupIn = MethodHandles.class.getMethod("privateLookupIn", Class.class, MethodHandles.Lookup.class)
20+
.invoke(null, clazz, lookup);
21+
return (MethodHandles.Lookup) privateLookupIn;
22+
}
23+
24+
static {
25+
MethodHandles.Lookup lookup = null;
26+
try {
27+
val field = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP");
28+
field.setAccessible(true);
29+
lookup = (MethodHandles.Lookup) field.get(null);
30+
} catch (Throwable t) {
31+
System.err.println("Failed to get MethodHandles.Lookup.IMPL_LOOKUP");
32+
t.printStackTrace();
33+
}
34+
IMPL_LOOKUP = lookup;
35+
}
36+
}

src/main/java/dev/minco/javatransformer/internal/util/UnsafeAccess.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/test/java/dev/minco/javatransformer/internal/util/ImplLookupTest.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)