Using equalsverifier with strongly encapsulate JDK internals

117 views
Skip to first unread message

zadorojna...@gmail.com

unread,
Aug 4, 2021, 11:18:05 AM8/4/21
to equalsverifier

Hi,

I'm using equalsverifier 3.7 to test a class that extends java.util.EventObject by adding few more custom fields.

With Java 8 everthing runs fine. After upgrading to Java 11 the test runs successfully, however I get the "An illegal reflective access operation" warning. In Java 16 the test fails without "--illegal-access=permit" or "--add-opens=java.base/java.util=ALL-UNNAMED" VM arguments. Using .withPrefabValues() doesn't seems to help either. In Java 17 --illegal-access option will not be there and --add-opens does not feel clean.

In general with Java 16, and later with Java 17, issues like above will arise more often for strongly encapsulated JDK classes.

Is there anything that can be done (apart from using --add-opens) to have such classes tested with equalsverifier?

Thanks!
EnhancedEventObject.java
EnhancedEventObjectTest.java

Jan Ouwens

unread,
Aug 9, 2021, 1:48:17 AM8/9/21
to equalsv...@googlegroups.com
Hi,

Sorry for the late reply, I was out of town for a few days.

In theory, in Java 16 and 17 EqualsVerifier should just work the way you're used to from Java 8. However, as you noted, the JDK team is working on encapsulating things, which makes it harder for EqualsVerifier to do its thing. It can't use reflection anymore to instantiate classes from the java.* packages. So, we have to provide prefab values for these classes. You can do it yourself by adding a .withPrefabValues() call to your EqualsVerifier invocation, but when it concerns Java classes, I consider it a bug if they don't work and I make sure the prefab value is added by default.

If you open an issue on the issue tracker at https://github.com/jqno/equalsverifier/issues, I can help you further. Please let me know there which class or classes are causing you problems, and post a small class that uses these classes, along with an equals method, that I can use to reproduce the issue.



Regards,
Jan
--
You received this message because you are subscribed to the Google Groups "equalsverifier" group.
To unsubscribe from this group and stop receiving emails from it, send an email to equalsverifie...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages