Hope I got the right mailing list, otherwise please direct me there.

Module.addOpens currently doesn't produce an illegal access warning if the target package has only be opened for illegal access.

Reproducer:

    import java.lang.reflect.Method;
    import java.net.URL;
    import java.net.URLClassLoader;

    public class NoIllegalWarning {
        public static void main(String[] args) throws Throwable {
            Class<?> clazz = URLClassLoader.class;
            addOpens(clazz);
            // Use
            Method m = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
            m.setAccessible(true);
            // invoke it here.
            System.out.println("done");
        }

        public static void addOpens(Class<?> target) {
            target.getModule().addOpens(target.getPackageName(), NoIllegalWarning.class.getModule());
        }
    }

In the current maser branch, it has to be executed with --illegal-access=permit.
Other than that, the code above doesn't display any warnings.
Removing the "addOpens" call will display a warning.
No subsequent illegal access warning is produced as the package is reflectively open now.

Could someone create a bug on JBS? I could not find an existing one there.
I did prepare a patch to fix this: https://github.com/DasBrain/jdk/compare/addOpens-illegalAccess

This is the kind of code I don't like to see in production.

- Johannes

Reply via email to