Backend Development 4 min read

Resolving IllegalAccessException When Using Caffeine Async Cache with Groovy on JDK Modules

This article explains how upgrading Java and Groovy dependencies caused an IllegalAccessException in Caffeine's asynchronous cache due to module encapsulation, and details the attempted fixes including JVM '--add-opens' arguments and dependency version adjustments.

FunTester
FunTester
FunTester
Resolving IllegalAccessException When Using Caffeine Async Cache with Groovy on JDK Modules

Java modularity, introduced in Java 9, splits the standard library into explicit modules, improving security, maintainability, and portability.

When upgrading the JDK, many projects encounter module‑related errors that require additional module configuration or JVM startup parameters.

During the use of Caffeine's asynchronous cache, an error occurred where an unnamed module could not access the jdk.proxy2 module.

Caused by: java.lang.IllegalAccessException: module jdk.proxy2 does not open jdk.proxy2 to unnamed module @6107227e

The problematic script is shown below:

static void main(String[] args) {
    LoadingCache
cache = Caffeine.newBuilder()
        .build(key -> {
            return "FunTester";
        });
    String value = cache.get("FunTester");
    System.out.println("缓存: " + value);
}

The full stack trace includes:

Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	... 23 more
Caused by: java.lang.IllegalAccessException: module jdk.proxy2 does not open jdk.proxy2 to unnamed module @6107227e
	at java.base/java.lang.invoke.MethodHandles.privateLookupIn(MethodHandles.java:259)
	... 28 more

One suggested fix is to add a JVM argument such as --add-opens jdk.proxy2/java.lang=ALL-UNNAMED , but because the module is already unnamed, the appropriate command was unclear.

Upgrading Caffeine to the latest version did not resolve the issue, so the Groovy version was locked at 3.0.9. After researching, the dependency was updated to a newer pre‑release:

<dependency>
    <groupId>org.apache.groovy</groupId>
    <artifactId>groovy</artifactId>
    <version>5.0.0-alpha-3</version>
</dependency>

Even after moving to the 5.x line, the problem persisted, highlighting the difficulty of mixing Java, Groovy, and module‑system constraints.

The issue is documented in the Apache Groovy tracker as "[JDK16] Illegal access to dynamic proxy" (GROOVY‑10137).

Javadependency managementcaffeineModule SystemGroovyJDK9
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.