DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=27468>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=27468 CachedXPathAPI not thread-save Summary: CachedXPathAPI not thread-save Product: XalanJ2 Version: 2.2.x Platform: PC OS/Version: Windows NT/2K Status: NEW Severity: Critical Priority: Other Component: org.apache.xpath AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] Version: Xalan bundled with jdk1.4.2_02 (crimson parser) Using an instance of the CachedXPathAPI class from within multiple threads on a document that is not changed at runtime, causes inconsistent behaviour. The source code below reproduces that problem on Windows NT (same is true for Linux RedHat7.3). Hint: I was only able to reproduce the problem when using a condition (e.g. [EMAIL PROTECTED]'a']) in the xpath statement. ---------------------------------------------------------- import java.io.*; import javax.xml.parsers.*; import org.apache.xpath.CachedXPathAPI; import org.w3c.dom.*; import org.xml.sax.*; public class CachedXPathAPITest { private static final String XML = "<document><node id='a'>a</node><node id='b'>b</node><node id='c'>c</node></document>"; private CachedXPathAPI _api; private Document _doc; public CachedXPathAPITest() throws Exception { _api = new CachedXPathAPI(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser = factory.newDocumentBuilder(); _doc = parser.parse(new InputSource(new StringReader(XML))); Thread t = null; for (int i=0; i<200; i++) t = new TestThread(_api, _doc); t.join(); } public static void main(String[] args) throws Exception { new CachedXPathAPITest(); } class TestThread extends Thread { private CachedXPathAPI _api; private Document _doc; TestThread(CachedXPathAPI api, Document doc) { _api = api; _doc = doc; start(); } public void run() { try { for (int i=0; i<100; i++) { String a = _api.eval(_doc, "/document/[EMAIL PROTECTED]'a']").str(); if (!a.equals("a")) throw new RuntimeException(a + "!=a"); String b = _api.eval(_doc, "/document/[EMAIL PROTECTED]'b']").str(); if (!b.equals("b")) throw new RuntimeException(b + "!=b"); String c = _api.eval(_doc, "/document/[EMAIL PROTECTED]'c']").str(); if (!c.equals("c")) throw new RuntimeException(c + "!=c"); } } catch (Exception e) { System.err.println(e); } } } }
