Our project has been faced a weird bug recently.
We are using Apache Xmlbeans to perform some xml construction. However, whenever it construct a complex type object, it mis-uses a different object implementation to do the construction. However, in Mac environment, it works correctly. We are using MyEclipse as our IDE.
We digged into the construction process. We found that the actual error was ClassNotFoundException. We do a bit of research on this. We found that the cause of the problem was on static inner class.
The thing is, we found that Java does not load the static inner class properly, in Windows JVM 1.5.11b03
The first resolution was to load the inner class explicitly before it does the actual call. So we grab the ClassLoader from the Outer class, and load it explicitly [further reading in P.S.]. At first, we thought the problem has been solved. But after tidy up the code and redeploy. It doesn't work again.
However, bugs always has a reason. We keep digging into the problem. At last, we found that the cause of the error was from MyEclipse IDE. The MyEclipse IDE is somehow doesn't compile the static inner class at the beginning, although it shows no compile error at design time. It looks like it happens occasionally as well. So at last, we compile it explicitly. Then jar the Xmlbeans generated files and do the reference from our project. At last, it is working fine!
P.S.
When we try to load up the inner class explicitly, we should use $ sign to refer inner class instead of . sign in ClassLoader.loadclass(String arg) method. The reason for this is because once the application started, the inner class been compiled. The reference to the inner class will use $ sign.
net.A.B -> net.A$B
Reference:
1) http://mail-archives.apache.org/mod_mbox/myfaces-users/200611.mbox/%3C885AADC3D2318E45807C702ABC2637DD133501@MOES0037.tcc.local%3E
2) http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4491755
No comments:
Post a Comment