10/09/2008

Solve java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy

I recently ran into this type of exceptions when experimenting with GlassFish V3. It turned out the root cause is that a class (HelloInterceptor) used in type-level @Interceptors annotation is missing in the WAR file. Once this class is packaged in the WAR file, it works.  In appservers that support EJB 3.1, EJB can be packaged inside a WAR file.

@Stateless
@Interceptors(HelloInterceptor.class)
public class HelloBean {
public String hello(String name) {
return "Hello, " + name;
}
}
ArrayStoreException has been in Java since JDK 1.0, but this is the first time I saw it. The javadoc says it is "[t]hrown to indicate that an attempt has been made to store the wrong type of object into an array of objects." So it's a low level exception that I would normally catch and shield it from client.

The stacktrace in server.log is pretty long, repeating the same stacktrace 3-4 times. In short it looks like this:
[#|2008-10-09T10:57:39.262-0400|SEVERE|GlassFish10.0|javax.enterprise.system.core|_ThreadID=17;_ThreadName=Thread-4;|
Exception while deploying the app
java.lang.RuntimeException: sun.reflect.annotation.TypeNotPresentExceptionProxy
at org.glassfish.javaee.core.deployment.JavaEEDeployer.loadMetaData(JavaEEDeployer.java:160)
at com.sun.enterprise.v3.server.ApplicationLifecycle.prepare(ApplicationLifecycle.java:436)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:180)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:314)
at com.sun.enterprise.v3.admin.CommandRunner$2.execute(CommandRunner.java:302)
at com.sun.enterprise.v3.admin.CommandRunner.doCommand(CommandRunner.java:312)
at com.sun.enterprise.v3.admin.CommandRunner.doCommand(CommandRunner.java:135)
at org.glassfish.deployment.autodeploy.AutoOperation.run(AutoOperation.java:122)
at org.glassfish.deployment.autodeploy.AutoDeployer.deploy(AutoDeployer.java:524)
at org.glassfish.deployment.autodeploy.AutoDeployer.deployAll(AutoDeployer.java:410)
at org.glassfish.deployment.autodeploy.AutoDeployer.run(AutoDeployer.java:342)
at org.glassfish.deployment.autodeploy.AutoDeployer.run(AutoDeployer.java:330)
at org.glassfish.deployment.autodeploy.AutoDeployService$1.run(AutoDeployService.java:200)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:653)
at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:460)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:286)
at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:222)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3072)
at java.lang.Class.getAnnotations(Class.java:3052)
at org.glassfish.apf.impl.AnnotationProcessorImpl.processAnnotations(AnnotationProcessorImpl.java:278)
at org.glassfish.apf.impl.AnnotationProcessorImpl.process(AnnotationProcessorImpl.java:188)
at org.glassfish.apf.impl.AnnotationProcessorImpl.process(AnnotationProcessorImpl.java:129)
at com.sun.enterprise.deployment.archivist.Archivist.processAnnotations(Archivist.java:476)
at com.sun.enterprise.deployment.archivist.Archivist.readAnnotations(Archivist.java:348)
at com.sun.enterprise.deployment.archivist.Archivist.readDeploymentDescriptors(Archivist.java:320)
at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:211)
at com.sun.enterprise.deployment.archivist.ApplicationFactory.openArchive(ApplicationFactory.java:143)
at org.glassfish.javaee.core.deployment.JavaEEDeployer.parseModuleMetaData(JavaEEDeployer.java:231)
at com.sun.enterprise.web.WebDeployer.parseModuleMetaData(WebDeployer.java:110)
Update on Mar 06, 2009: I ran into ArrayStoreException again. This time I used type-level @Remote and @Local on bean class but forgot to include the remote and local business interface classes into the WAR file:
@Remote(HelloRemote.class)
@Local(HelloLocal.class)
public class HelloBean {
public String hello(String name) {
return "Hello, " + name;
}