Skip to content
Permalink
Browse files

[#57] Illegal reflective access when running jOOR-java-8 on Java 10

  • Loading branch information...
lukaseder committed Sep 24, 2019
1 parent 4b29a04 commit 56b8dee699ac992f84d4a55b180bbc25ec2c5a55
@@ -25,6 +25,7 @@
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
// ...

/**
* A wrapper for an {@link Object} or {@link Class} upon which reflective calls
@@ -299,6 +300,16 @@ private static Reflect on(Class<?> type, Object object) {
















@@ -183,4 +183,3 @@




@@ -185,4 +185,3 @@




@@ -55,7 +55,7 @@
*/
public class ReflectTest {

static final boolean JDK9 = false ;
static final boolean JDK9 = false;

@Rule
public final ExpectedException expectedException = ExpectedException.none();
@@ -25,6 +25,7 @@
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;

/**
* A wrapper for an {@link Object} or {@link Class} upon which reflective calls
@@ -295,10 +296,20 @@ private static Reflect on(Class<?> type, Object object) {


try {
result = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class);
try {
Optional.class.getMethod("stream");
result = null;
}

if (!result.isAccessible())
result.setAccessible(true);
// [jOOQ/jOOR#57] [jOOQ/jOOQ#9157]
// A JDK 9 guard that prevents "Illegal reflective access operation"
// warnings when running the below on JDK 9+
catch (NoSuchMethodException e) {
result = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class);

if (!result.isAccessible())
result.setAccessible(true);
}
}

// Can no longer access the above in JDK 9
@@ -55,7 +55,7 @@
*/
public class ReflectTest {

static final boolean JDK9 = false ;
static final boolean JDK9 = false;

@Rule
public final ExpectedException expectedException = ExpectedException.none();
@@ -25,6 +25,7 @@
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;

/**
* A wrapper for an {@link Object} or {@link Class} upon which reflective calls
@@ -295,10 +296,20 @@ private static Reflect on(Class<?> type, Object object) {
else
/* [/java-9] */
try {
result = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class);
try {
Optional.class.getMethod("stream");
result = null;
}

if (!result.isAccessible())
result.setAccessible(true);
// [jOOQ/jOOR#57] [jOOQ/jOOQ#9157]
// A JDK 9 guard that prevents "Illegal reflective access operation"
// warnings when running the below on JDK 9+
catch (NoSuchMethodException e) {
result = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class);

if (!result.isAccessible())
result.setAccessible(true);
}
}

// Can no longer access the above in JDK 9

0 comments on commit 56b8dee

Please sign in to comment.
You can’t perform that action at this time.