Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lukaseder opened this issue Jun 21, 2018 · 2 comments

Comments

@lukaseder
Copy link
Member

commented Jun 21, 2018

jOOR-java-8's static initialiser runs a reflective access:

    static {
        Constructor<MethodHandles.Lookup> result;

        /* [java-9] */
        if (true)
            result = null;
        else
        /* [/java-9] */
        try {
            // The following call is a problem:
            result = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class);

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

        // Can no longer access the above in JDK 9
        catch (Throwable ignore) {
            result = null;
        }

        CACHED_LOOKUP_CONSTRUCTOR = result;
    }

As can be seen, the modularised Java 9 distribution doesn't run this check. Also, the Java 6 distribution doesn't run it. The entire initialiser is removed from the Java 6 distribution. While this check is OK to run on a JDK 8, people might use the Java 8 distribution also on Java 9. We should replace the compile-time preprocessing "check" by a runtime check:

    static final boolean                           JAVA_9;

    static {

        // Runtime detection if we're on Java 9
        boolean java9;

        try {
            Optional.class.getMethod("stream");
            java9 = true;
        }
        catch (NoSuchMethodException e) {
            java9 = false;
        }

        JAVA_9 = java9;

        Constructor<MethodHandles.Lookup> result = null;

        if (!java9) {
            try {
                result = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class);

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

            // Can no longer access the above in JDK 9
            catch (Throwable ignore) {
            }
        }

        CACHED_LOOKUP_CONSTRUCTOR = result;
    }

This issue is also present in jOOQ, where the shaded jOOR dependency doesn't have a Java 9 version yet:
jOOQ/jOOQ#7594

@lukaseder lukaseder added this to the Version 0.9.10 milestone Jun 21, 2018
lukaseder added a commit that referenced this issue Jun 21, 2018
@lukaseder lukaseder added the R: Fixed label Jun 21, 2018
@lukaseder lukaseder closed this Jun 21, 2018
@lukaseder lukaseder added R: Wontfix and removed R: Fixed labels Jun 21, 2018
lukaseder added a commit that referenced this issue Jun 21, 2018
…ava 10"

This reverts commit 4f66d73.
@lukaseder

This comment has been minimized.

Copy link
Member Author

commented Jun 21, 2018

This cannot be implemented. If the reflective logic is not present in the JDK 8 distribution, then there is no way to call interface default methods at all. We can live with this limitation. People using JDK9+ should upgrade to the JDK9+ distribution.

@lukaseder lukaseder added R: Wontfix and removed R: Wontfix labels Jun 21, 2018
@lukaseder lukaseder removed the R: Wontfix label Nov 19, 2018
@lukaseder lukaseder added the R: Fixed label Dec 4, 2018
@lukaseder lukaseder removed the R: Fixed label Sep 24, 2019
@lukaseder lukaseder reopened this Sep 24, 2019
@lukaseder

This comment has been minimized.

Copy link
Member Author

commented Sep 24, 2019

The issue is causing trouble in the jOOQ Open Source Edition: jOOQ/jOOQ#9157

We'll fix it with the additional guard. It will remain a known issue when using the Java 8 distribution on JDK 11, as we cannot use JDK 11 API, but that's solveable by upgrading the distribution in both jOOQ and jOOR.

The fix will at least get rid of the warning for the majority of people who do not depend on this lookup constructor feature.

@lukaseder lukaseder added the R: Fixed label Sep 24, 2019
lukaseder added a commit to jOOQ/jOOQ that referenced this issue Sep 24, 2019
Prevent 'Illegal reflective access operation' warning in jOOQ Open Source Edition
lukaseder added a commit to jOOQ/jOOQ that referenced this issue Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.