Skip to content

AbstractThrowableAssert#isInstanceOf() throws IllegalAccessErrorΒ #1656

@leadpony

Description

@leadpony

Summary

AbstractThrowableAssert#isInstanceOf() throws an IllegalAccessError exception
when assertj-core is used as a modular jar.

Example

Throwable thrown = new IllegalArgumentException();
assertThat(thrown).isInstanceOf(NullPointerException.class);

Building and runing this example with JDK 9 or higher:

mvn package
java -p target/modules -m example/example.Example

outputs the following error messages:

Exception in thread "main" java.lang.IllegalAccessError: class org.assertj.core.util.Closeables (in module org.assertj.core) cannot access class java.util.logging.Logger (in module java.logging) because module org.assertj.core does not read module java.logging
	at org.assertj.core@3.14.0-SNAPSHOT/org.assertj.core.util.Closeables.<clinit>(Closeables.java:25)
	at org.assertj.core@3.14.0-SNAPSHOT/org.assertj.core.util.Throwables.getStackTrace(Throwables.java:172)
	at org.assertj.core@3.14.0-SNAPSHOT/org.assertj.core.error.ShouldBeInstance.<init>(ShouldBeInstance.java:67)
	at org.assertj.core@3.14.0-SNAPSHOT/org.assertj.core.error.ShouldBeInstance.shouldBeInstance(ShouldBeInstance.java:34)
	at org.assertj.core@3.14.0-SNAPSHOT/org.assertj.core.internal.Objects.assertIsInstanceOf(Objects.java:136)
	at org.assertj.core@3.14.0-SNAPSHOT/org.assertj.core.api.AbstractAssert.isInstanceOf(AbstractAssert.java:382)
	at example@1.0.0-SNAPSHOT/example.Example.main(Example.java:9)

The problem happens because org.assertj.core.util.Closeables requires java.logging module both at compile-time and at runtime.
Adding the following line to src/main/java9/module-info.java in asssertj-core repository will resolve the problem.

requires java.logging;

Please find the attached project which reproduces the problem.
assertj-example.zip

Thank you.

Metadata

Metadata

Assignees

Labels

language: Java 9+An issue related to using AssertJ with Java 9 or newertheme: module systemAn issue related to the Java module system

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions