Bugs item #1618750, was opened at 2006-12-19 14:46 Message generated for change (Comment added) made by petehak You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=116035&aid=1618750&group_id=16035
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Andre Nurzenski (nurzensa) Assigned to: Nobody/Anonymous (nobody) Summary: ClassCastException while creating org.dom4j.DocumentFactory Initial Comment: I am using dom4j 1.6.1 within an OSGi-Bundle in a rich client application. When running the application, the following call causes a DocumentException: SAXReader saxReader = new SAXReader(); Document document = saxReader.read(InputStream); The DocumentException contains a nested ClassCastException: java.lang.ClassCastException: org.dom4j.DocumentFactory at org.dom4j.DocumentFactory.getInstance(DocumentFactory.java:97) at org.dom4j.io.SAXReader.getDocumentFactory(SAXReader.java:645) at org.dom4j.io.SAXReader.createContentHandler(SAXReader.java:969) at org.dom4j.io.SAXReader.read(SAXReader.java:449) at org.dom4j.io.SAXReader.read(SAXReader.java:343) The cause of this exception seems to be the way the DocumentFactory class is loaded in org.dom4j.util.SimpleSingleton, line 38, using the context class loader. When using Class.forName() to load the class (same way as in 1.6), the problem does not occur. As this seems to be a very special problem within an OSGi-Environment and its class loading mechanism, I'm not sure if this issue can be considered as a bug. Please contact me if you need further information. ---------------------------------------------------------------------- Comment By: Pete (petehak) Date: 2007-12-19 10:42 Message: Logged In: YES user_id=1962444 Originator: NO Is DocumentFactory thread-safe? I removed its internal use of SimpleSingleton and replaced it with static class to store one DocumentFactory instance. Can I use the same DocumentFactory instance for concurrent threads or should there be one DocumentFactory per thread? If that class is not thread-safe, then this fix is not applicable. We have to find some other way, like discarding the caching compleletely and create a new instance of DocumentFactory for each call. This naturally comes with a performance penalty, but how big, i dunno. ---------------------------------------------------------------------- Comment By: Filip Jirsák (filipjirsak) Date: 2007-12-18 13:17 Message: Logged In: YES user_id=1175071 Originator: NO May be this is bug in dom4j. Though you can pass on DocumentFactory when creating SAXParser – dom4j doesn't need creating its own instance of DocumentFactory with buggy singleton afterwards. You can try this: DocumentFactory documentFactory = new DocumentFactory(); SAXReader saxReader = new SAXReader(documentFactory); Document document = saxReader.read(InputStream); DocumentFactory should be singleton better, but you can manage it your correct way. For example: public class DocumentFactorySingleton { public static DocumentFactory instance = new DocumentFactory(); } SAXReader saxReader = new SAXReader(DocumentFactorySingleton.instance); Document document = saxReader.read(InputStream); ---------------------------------------------------------------------- Comment By: Pete (petehak) Date: 2007-12-18 12:58 Message: Logged In: YES user_id=1962444 Originator: NO We have run into this same problem with Weblogic Server 10.0, Dom4j 1.6.1 contained in several EAR files. The occurrence of the problem seems quite random. We can test applications for days, and then suddenly this exception is thrown. After a Weblogic reboot, everything works fine, until the problem occurs again after some period of time. We must do something about this. Should we include dom4j in system classpath, change Dom4j's class loading behavior described in this thread (Class.forName..) or what? ---------------------------------------------------------------------- Comment By: shakebaby (shakebaby) Date: 2007-08-20 05:56 Message: Logged In: YES user_id=1871087 Originator: NO I met this with the same environment.I don't know why. I guess it may be a bug . Can any one give me a reply please ? Thank you ! ---------------------------------------------------------------------- Comment By: Kevin Galligan (kpgalligan) Date: 2007-03-19 02:46 Message: Logged In: YES user_id=102538 Originator: NO I'm having the same problem. Just started out of nowhere. I had installed jdk1.6, then tried to uninstall it and put 1.5 back, and ever since that happened there have been problems. My code was working before, though, so this is a little frustrating. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=116035&aid=1618750&group_id=16035 ------------------------------------------------------------------------- SF.Net email is sponsored by: Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace _______________________________________________ dom4j-dev mailing list dom4j-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/dom4j-dev