Adam Bien's Weblog
GlassFish / Jersey Exception "java.lang.IllegalArgumentException: object is not an instance of declaring class" And Solution
The exception:
SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
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:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
[…]
is caused by exposing EJB 3.1 methods directly via REST without having a no-interface view declared. This happens when your EJB 3.1 REST-endpoint implements an additional interface without declaring the no-interface view:
import javax.ejb.*;
@Path("RESTafari)
@Singleton
public class RESTEndpoint implements SomeLocalInterface{}
Adding a @LocalBean annotation (and activating the no-interface view) solves the problem:
import javax.ejb.*;
@LocalBean
@Path("RESTafari)
@Singleton
public class RESTEndpoint implements SomeLocalInterface{}
Posted at 09:22AM Jan 30, 2012 by Adam Bien in Real World Java EE Patterns - Rethinking Best Practices | Comments[3] | Views/Hits: 7770
NEW Workshop: "JPA, NoSQL, Caching, Grids and Distributed Caches with Java EE 7", May 7th, 2013, Airport Munich
A book about rethinking Java EE Patterns
Tweet Follow @AdamBien

This is indeed very discouraging. I faced the same problem when working with local EJB - the simple stateless bean implementing some non-ejb interface must be annotated with @LocalBean to provide the possibility to inject bean through CDI. The exception was non-intuitive and it took long time for me to get the reason. As I saw in weld forum Gavin King was too sorry about this as he was against such additional actions and wanted to avoid additional annotations in this case.
Posted by Anton on February 01, 2012 at 08:27 AM CET #
Thank you! You make my day!
Posted by Hendrik on May 02, 2012 at 12:34 PM CEST #
Thanks
Should I annotate my facade Ejb which is a REST interface to my other Local Ejb with @LocalBean ?
Posted by Ehsun on April 19, 2013 at 05:19 PM CEST #