title

fire chief's random developer tidbits

Thursday, March 8, 2012

IllegalAccessError when accessing an enum type in a switch statement

We got this error:  java.lang.IllegalAccessError: com/mycompany/MySessionBean$1 when using a switch statement on an Enum inside a stateless session bean.  It took some puzzling, but the answer ended up being that Java builds an anonymous class internally to handle the switch on enum.  We were accidentally deploying two copies of the $1 class file due to Maven's default excludes on ejb-client not excluding these.  Our ear has an application client which needs an ejb-client jar version of the main ejb jar.  The client jar had a copy of the $1 class when it should not have.  The fix was to include <clientExclude>**/*Bean$*.class</clientExclude> in the ejb-jar plugin config, along with all the maven default configs.

The root cause of this may be that there were different classloaders in Glassfish loading separate copies of the class.

No comments:

Post a Comment