ClassCastException after moving a webapp from Tomcat to Glassfish
I started playing around with Glassfish this week, with the idea of moving all my webapps currentlty running on an Apache Tomcat server to it.
I started by deploying a very simple JSF application on GlassfishV2UR1. At first everything seemed to work correctly, but I quickly noticed that the 2nd user hitting the application would cause a "ClassCastExcpetion" to be raised.
I started debugging my application and I pinpointed the line of code where the excpetion was raised to the cast below:
// Iterate through a List...
c1= (Class1) o;
As you can see, this is a very innocent cast which shouldn't be causing any problem whatsoever. I first thought I was hitting some sort of bug in the JRE, but I could qickly exlclude this as a root cause of the problem because of the fact that when running the application in Tomcat with the very same JRE the error wouldn't occur.
So, it had to be down to some sort of difference between Glassfish and Tomcat. The only other difference I could think of was a different behavior of the ClassLoaders which could lead to an issue with similar symptoms.
To cut a very long story short, what I had to do was to change the <class-loader delegate> property in sun-web.xml from true to false. After this change my webapp started behaving reasonbly again. As of this writing I haven't found out what the root cause of the issue is. If somebody's got an explanation for this, I'll be more then happy to mention it here.
|