equalsverifier: Update from 2.4.4 to 2.4.7 broke Java11 compatibility (Could not find sun.misc.Unsafe)
What steps will reproduce the problem?
We updated equalsverifier from 2.4.4 to 2.4.7.
What is the code that triggers this problem?
All our 54 unit tests calling equalsverifier.
Provide an example of a complete class (equals method, hashCode method, relevant fields) and a call to EqualsVerifier.
@Test
public void testEqualsContract() {
TestUtils.assumeWorkingEqualsVerifier();
EqualsVerifier.forClass(NodePair.class).usingGetClass()
.suppress(Warning.ANNOTATION) // FIXME: remove it after https://github.com/jqno/equalsverifier/issues/152 is fixed
.withPrefabValues(Node.class, new Node(1), new Node(2))
.verify();
}
What error message or stack trace does EqualsVerifier give?
java.lang.UnsupportedOperationException: Cannot define class using reflection: Could not find sun.misc.Unsafe
at nl.jqno.equalsverifier.internal.lib.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$Initializable$Unavailable.defineClass(ClassInjector.java:334)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.dynamic.loading.ClassInjector$UsingReflection.inject(ClassInjector.java:187)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default$InjectionDispatcher.load(ClassLoadingStrategy.java:205)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:79)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:4247)
at nl.jqno.equalsverifier.internal.reflection.Instantiator.giveDynamicSubclass(Instantiator.java:91)
at nl.jqno.equalsverifier.internal.reflection.Instantiator.instantiateAnonymousSubclass(Instantiator.java:70)
at nl.jqno.equalsverifier.internal.reflection.ObjectAccessor.copyIntoAnonymousSubclass(ObjectAccessor.java:109)
at nl.jqno.equalsverifier.internal.checkers.HierarchyChecker.checkSubclass(HierarchyChecker.java:122)
at nl.jqno.equalsverifier.internal.checkers.HierarchyChecker.check(HierarchyChecker.java:46)
at nl.jqno.equalsverifier.EqualsVerifier.verifyWithExamples(EqualsVerifier.java:425)
at nl.jqno.equalsverifier.EqualsVerifier.performVerification(EqualsVerifier.java:387)
at nl.jqno.equalsverifier.EqualsVerifier.verify(EqualsVerifier.java:358)
What did you expect?
No error (as for 2.4.4)
Which version of EqualsVerifier are you using?
2.4.7
Please provide any additional information below.
Java 11 EA build 19. No problem with Java 8, 9, 10.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 21 (15 by maintainers)
Commits related to this issue
- see #16047 - update to equalsverifier 2.4.8 for Java 11 compatibility, see https://github.com/jqno/equalsverifier/issues/197 git-svn-id: https://josm.openstreetmap.de/svn/trunk@14002 0c6e7542-c601-04... — committed to JOSM/josm by don-vip 6 years ago
- see #16047 - update to equalsverifier 2.4.8 for Java 11 compatibility, see https://github.com/jqno/equalsverifier/issues/197 git-svn-id: https://josm.openstreetmap.de/svn/trunk@14002 0c6e7542-c601-04... — committed to floscher/josm by don-vip 6 years ago
- add workaround to https://github.com/jqno/equalsverifier/issues/197 git-svn-id: https://josm.openstreetmap.de/svn/trunk@14004 0c6e7542-c601-0410-84e7-c038aed88b3b — committed to JOSM/josm by don-vip 6 years ago
- add workaround to https://github.com/jqno/equalsverifier/issues/197 git-svn-id: https://josm.openstreetmap.de/svn/trunk@14004 0c6e7542-c601-0410-84e7-c038aed88b3b — committed to floscher/josm by don-vip 6 years ago
Plan for world domination:
Thanks a lot Rafael! It’s very nice to see upstream developers helping downstream projects 👍
@raphw Thanks again for the suggestion: I was able to completely remove the (direct) dependency on ASM, the code is now easier to comprehend, and it’s also about 60 lines shorter. A nice improvement!
As simple as:
If several classes have the same class loader, it helps to reuse the type pool as it caches classes internally.
You can probably use
TypePool.Default.WithLazyResolution
if you filter many annotations by name. This avoid I/O until you are using a property. You can also load annotations once you looked them up, eg:Byte Buddy also detects if the current VM supports type annotations and makes them available on demand. (Important difference: calling
getDeclaredAnnotations()
on aTypeDescription.Generic
returns type annotations, on a non-genericTypeDescription
, it returns regular annotations.PS I found a way to make the ANNOTATION warning obsolete, so I removed it from the API entirely. So, now you’ll have to remove that suppression 😉.
I decided to release with ASM’s experimental Java 11 support for now after all, since Java 11 is now officially out. I’ll do a new release some time after ASM comes with an update.
Check out version 3.0 😃
Also, I guess you can now remove that suppress warning line 😉
Thanks for reporting this. In fact, I was already working on support for Java 11. (I hope to be able to finish and release that before I go on vacation: 🤞)
I’m surprised, though, that 2.4.4 works on Java 11. I would have expected 2.4.4 to fail as well.