IllegalArgumentException: object is not an instance of declaring class

1,091 views
Skip to first unread message

Marco Luca Sbodio

unread,
Aug 3, 2016, 7:26:26 AM8/3/16
to equalsverifier
Hi there,

I'm trying EqualsVerifier 2.1.4, and I have some troubles understanding  why I get the error message in the subject. I created a simple class which gives that error:

public class AClass {

	private final List<String> aList;

	public AClass(List<String> aList) {
		this.aList = aList;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((aList == null) ? 0 : aList.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) return true;
		if (obj == null) return false;
		if (getClass() != obj.getClass()) return false;
		AClass other = (AClass) obj;
		if (aList == null) {
			if (other.aList != null) return false;
		} else if (!aList.equals(other.aList)) return false;
		return true;
	}

	@Override
	public String toString() {
		return "AClass [aList=" + aList + "]";
	}

}

and the corresponding test case:

public class AClassTest {

	@Test
	public void test() {
		EqualsVerifier.forClass(AClass.class).verify();
	}

}

I've noticed that if I declare the class _final_ then everything is OK. Why?

Full exception stack trace:

java.lang.AssertionError: IllegalArgumentException: object is not an instance of declaring class
at nl.jqno.equalsverifier.EqualsVerifier.handleError(EqualsVerifier.java:381)
at nl.jqno.equalsverifier.EqualsVerifier.verify(EqualsVerifier.java:370)
at my.package.AClassTest.test(AClassTest.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:507)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:507)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.description.type.TypeDescription$Generic$AnnotationReader$ForTypeArgument.resolve(TypeDescription.java:3873)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.description.type.TypeDescription$Generic$AnnotationReader$Delegator$Chained.resolve(TypeDescription.java:3504)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.description.type.TypeDescription$Generic$AnnotationReader$ForTypeArgument.resolve(TypeDescription.java:3833)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.description.type.TypeDescription$Generic$AnnotationReader$Delegator.asList(TypeDescription.java:3475)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.description.type.TypeDescription$Generic$OfNonGenericType$ForLoadedType.getDeclaredAnnotations(TypeDescription.java:4227)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.implementation.attribute.AnnotationAppender$ForTypeAnnotations.apply(AnnotationAppender.java:718)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.implementation.attribute.AnnotationAppender$ForTypeAnnotations.onNonGenericType(AnnotationAppender.java:699)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.implementation.attribute.AnnotationAppender$ForTypeAnnotations.onNonGenericType(AnnotationAppender.java:413)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.description.type.TypeDescription$Generic$OfNonGenericType.accept(TypeDescription.java:4094)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.implementation.attribute.AnnotationAppender$ForTypeAnnotations.onParameterizedType(AnnotationAppender.java:680)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.implementation.attribute.AnnotationAppender$ForTypeAnnotations.onParameterizedType(AnnotationAppender.java:413)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.description.type.TypeDescription$Generic$OfParameterizedType.accept(TypeDescription.java:5017)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.implementation.attribute.MethodAttributeAppender$ForInstrumentedMethod.apply(MethodAttributeAppender.java:187)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.dynamic.scaffold.TypeWriter$MethodPool$Record$ForDefinedMethod$WithBody.applyBody(TypeWriter.java:581)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.dynamic.scaffold.TypeWriter$MethodPool$Record$ForDefinedMethod.apply(TypeWriter.java:517)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.dynamic.scaffold.TypeWriter$Default$ForCreation.create(TypeWriter.java:3799)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.dynamic.scaffold.TypeWriter$Default.make(TypeWriter.java:1617)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.dynamic.scaffold.subclass.SubclassDynamicTypeBuilder.make(SubclassDynamicTypeBuilder.java:172)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.dynamic.scaffold.subclass.SubclassDynamicTypeBuilder.make(SubclassDynamicTypeBuilder.java:153)
at nl.jqno.equalsverifier.internal.lib.bytebuddy.dynamic.DynamicType$Builder$AbstractBase.make(DynamicType.java:2566)
at nl.jqno.equalsverifier.internal.Instantiator.giveDynamicSubclass(Instantiator.java:98)
at nl.jqno.equalsverifier.internal.Instantiator.instantiateAnonymousSubclass(Instantiator.java:82)
at nl.jqno.equalsverifier.internal.ObjectAccessor.copyIntoAnonymousSubclass(ObjectAccessor.java:126)
at nl.jqno.equalsverifier.HierarchyChecker.checkSubclass(HierarchyChecker.java:129)
at nl.jqno.equalsverifier.HierarchyChecker.check(HierarchyChecker.java:57)
at nl.jqno.equalsverifier.EqualsVerifier.verifyWithExamples(EqualsVerifier.java:431)
at nl.jqno.equalsverifier.EqualsVerifier.performVerification(EqualsVerifier.java:393)
at nl.jqno.equalsverifier.EqualsVerifier.verify(EqualsVerifier.java:364)
... 24 more

Thank you in advance!
Marco

Jan Ouwens

unread,
Aug 3, 2016, 9:52:24 AM8/3/16
to equalsv...@googlegroups.com, Marco Luca Sbodio
Hm, this is very strange. I can't reproduce it locally.

Is this something that occurs in your IDE, or on the command-line from a build script, or both? Which IDE, JVM and OS do you use?

The reason why the error doesn't occur if you make the class final, is because this error occurs when EqualsVerifier tries to create a subclass of AClass, to do some inheritance-related tests. If AClass is final, that's obviously doesn't need to happen.


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.
For more options, visit https://groups.google.com/d/optout.

Marco Luca Sbodio

unread,
Aug 3, 2016, 3:37:47 PM8/3/16
to equalsverifier, marco....@gmail.com
Hi Jan,

thank you for the quick reply. I'm using:

- Ubuntu 14.04
- Eclipse Mars.2 Release (4.5.2)
- Java 8, IBM JVM:
java version "1.8.0"
Java(TM) SE Runtime Environment (build pxa6480sr1fp10-20150711_01(SR1 FP10))
IBM J9 VM (build 2.8, JRE 1.8.0 Linux amd64-64 Compressed References 20150630_255633 (JIT enabled, AOT enabled)
J9VM - R28_jvm.28_20150630_1742_B255633
JIT  - tr.r14.java_20150625_95081.01
GC   - R28_jvm.28_20150630_1742_B255633_CMPRSS
J9CL - 20150630_255633)
JCL - 20150711_01 based on Oracle jdk8u51-b15

Marco

Jan Ouwens

unread,
Aug 3, 2016, 3:42:13 PM8/3/16
to equalsverifier, marco....@gmail.com
Hi Marco,

Thanks for the info. Can you tell me whether you encouter this in Eclipse, on the command-line (from Ant/Maven/Gradle?), or both?

I'll look into this and will let you know if I find an answer for you.


Jan

Marco Luca Sbodio

unread,
Aug 4, 2016, 5:19:07 AM8/4/16
to equalsverifier, marco....@gmail.com
Hi Jan,

thank you! I got the error when running the JUnit test from within Eclipse.


don't know if it's related.

Cheers,
Marco

Jan Ouwens

unread,
Aug 6, 2016, 10:36:40 AM8/6/16
to equalsverifier, marco....@gmail.com
Hi Marco,

I took a look at it, but I still can't reproduce it, unfortunately.
It seems like the problem occurs when ByteBuddy (one of EqualsVerifier's dependencies) tries to access annotations on the class or one of its fields (or one of its fields's fields). Is your class using any annotations?

Unfortunately, I don't have enough information right now to figure it out any further. Maybe you can make a small, self-contained project on GitHub that reproduces this issue? By that I mean a project that's a complete project in that it has a build script with all the necessary dependencies so I can run it from the command-line or import it into Eclipse without modifications, and small in that it (ideally) only has enough code that's needed to actually reproduce the issue.

I feel like there's something in the environment of the code that's causing this, and making such a project will help sniff it out.

Cheers,
Jan

Jan Ouwens

unread,
Aug 6, 2016, 11:37:02 AM8/6/16
to equalsverifier, marco....@gmail.com
Hi Marco,

Another quick update. I just tried to run EqualsVerifier on my other computer, which has an older version of Java 8 (specifically: Java 1.8.0_11) and I was getting errors similar to the one you report (though not exactly the same). When I updated to a more recent version of Java 8 (1.8.0_101) the errors disappeared. Travis CI, which I use to verify my builds, uses Java 1.8.0_31, and there it's also fine. These are all Oracle JVMs, btw.

So maybe we have to look for the problem there!


Cheers,
Jan

Jan Ouwens

unread,
Aug 6, 2016, 11:48:24 AM8/6/16
to equalsverifier, marco....@gmail.com
OK, final e-mail on this topic for now, I promise ;).

On the ByteBuddy issue tracker, I found someone who had a similar problem to yours: https://github.com/raphw/byte-buddy/issues/144

There, too, it was caused by an older Java 8 JVM. ByteBuddy's maintainer says he's considered patching things up for older versions of Java 8, but it would be too much work so he decided against it.

I guess the only way to solve your issue then, is to update your JVM.


Cheers
Jan

Marco Luca Sbodio

unread,
Sep 5, 2016, 9:08:04 AM9/5/16
to equalsverifier, marco....@gmail.com
Thank you Jan! ... and sorry for the late reply.

I will check with future updates of the JVM - can't update now, because it's a production system.

Cheers,
Marco
Reply all
Reply to author
Forward
0 new messages