Skip to content

Java 16 and strongly encapsulated Java internals causing problems with MethodHandle lookup #615

@opeongo

Description

@opeongo

Project Jigsaw introduced modules and the access issues that come with them. Things changed again in Java 16 as strongly encapsulated internals became the default. Interfaces can be accessed from a module that is exported, but the implementation might be in a module that is not exported.

The following BeanShell example succeeded on Java versions 8 to 15, but fails on Java 16+.

import javax.xml.parsers.DocumentBuilderFactory;
import org.xml.sax.InputSource;

dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
dbf.setNamespaceAware(true);
dbf.setFeature("http://xml.org/sax/features/namespaces", false);
dbf.setFeature("http://xml.org/sax/features/validation", false);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
docBuilder = dbf.newDocumentBuilder();
doc = docBuilder.parse(new InputSource(input));
nodes = doc.getElementsByTagName("mapID");

This code will fail with IllegalAccessException on Java 16+

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions