java.lang.IllegalArgumentException: object is not an instance of declaring class

Apache's JIRA Issue Tracker | Laura Dean | 6 years ago
  1. 0

    [GROOVY-4832] when two java classes extend a groovy class, both subclasses have a metaClass for whichever subclass was loaded first - ASF JIRA

    apache.org | 1 year ago
    java.lang.IllegalArgumentException: object is not an instance of declaring class
  2. 0

    *Original problem:* I have an abstract groovy class, and two (or more) concrete java subclasses extend it. The superclass has an abstract method, which each concrete subclass overrides (of course). When I use just one subclass, everything works fine: I call a superclass method that calls the abstract method, and I get the behavior I expect. But when the other subclass has already been loaded, things are different. Then, I get an IllegalArgumentException: object is not an instance of declaring class. This problem corresponds to testGenericSubclassWithBafflingSymptom() in the attached junit tests. See that test for additional details. *Simpler case that illustrates the likely underlying problem (and does not involve generics):* I have an abstract groovy class, and two concrete java subclasses extend it. If I have an instance of just one of the subclasses, then instance.metaClass.theClass returns exactly what I expect. But if I've already loaded the other subclass, then the metaClass on an instance of *either* subclass is for the class that was used first! {code:java} // snippet of the groovy version of testSubclass(), also attached OtherConcreteJavaSubclass unrelatedInstance = new OtherConcreteJavaSubclass(); ConcreteJavaSubclass instance = new ConcreteJavaSubclass(); assertEquals("this one works", OtherConcreteJavaSubclass, unrelatedInstance.metaClass.theClass) assertEquals("but this one is wrong", ConcreteJavaSubclass, instance.metaClass.theClass) {code} This mixture of groovy and java may sound a little odd, but we actually ran into it when converting an existing class from java to groovy, and it stumped us for quite a while.

    Apache's JIRA Issue Tracker | 6 years ago | Laura Dean
    java.lang.IllegalArgumentException: object is not an instance of declaring class
  3. 0

    WebappMetricsFilter : IllegalArgumentException: object is not an instance of declaring class

    GitHub | 4 years ago | udgupta
    java.lang.IllegalArgumentException: object is not an instance of declaring class
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Spring+JPA+DAO+Tomcat

    Stack Overflow | 5 years ago | Ivan
    java.lang.IllegalArgumentException: object is not an instance of declaring class
  6. 0

    What Jersey doesn't like in my Stateless Session Bean?

    Stack Overflow | 6 years ago | yegor256
    java.lang.IllegalArgumentException: object is not an instance of declaring class

  1. Aria Pahlavan 16 times, last 2 weeks ago
  2. kjhdofjosvs 2 times, last 1 month ago
  3. tyson925 2 times, last 1 month ago
  4. kuldeep 2 times, last 2 months ago
  5. aldrinleal 1 times, last 5 months ago
6 more registered users
72 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.IllegalArgumentException

    object is not an instance of declaring class

    at sun.reflect.NativeMethodAccessorImpl.invoke0()
  2. Java RT
    Method.invoke
    1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    4. java.lang.reflect.Method.invoke(Method.java:597)
    4 frames
  3. Groovy
    AbstractCallSite.callCurrent
    1. org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:226)
    2. org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:52)
    3. org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:145)
    3 frames