Uploaded image for project: 'XMLBeans'
  1. XMLBeans
  2. XMLBEANS-84

Cannot run XmlObject.selectPath using Jaxen in multi threaded environment

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • Version 1.0.3
    • Version 2 Beta 1
    • XPath
    • None
    • Win2k, JDK 1.4.2_06

    Description

      Whe using complex XPATH which fires Jaxen under the covers is causing problems in Multithreaded environment. The following stack trace:

      C:\j2sdk1.4.2\bin\java -Didea.launcher.port=7543 -Didea.launcher.library=C:\IntelliJ-EAP\bin\breakgen.dll -Dfile.encoding=windows-1252 -classpath C:\j2sdk1.4.2\jre\lib\charsets.jar;C:\j2sdk1.4.2\jre\lib\jce.jar;C:\j2sdk1.4.2\jre\lib\jsse.jar;C:\j2sdk1.4.2\jre\lib\plugin.jar;C:\j2sdk1.4.2\jre\lib\rt.jar;C:\j2sdk1.4.2\jre\lib\sunrsasign.jar;C:\j2sdk1.4.2\jre\lib\ext\dnsns.jar;C:\j2sdk1.4.2\jre\lib\ext\ldapsec.jar;C:\j2sdk1.4.2\jre\lib\ext\localedata.jar;C:\j2sdk1.4.2\jre\lib\ext\sunjce_provider.jar;D:\GOLD\test\application\classes;D:\GOLD\application\classes;C:\src\IdeaProjects\GOLD\extlib\sun\jars\mail-1.3.1.jar;C:\src\IdeaProjects\GOLD\extlib\sun\jars\activation-1.0.2.jar;D:\GOLD\common\classes;C:\src\IdeaProjects\GOLD\extlib\commons-beanutils\jars\commons-beanutils-1.6.jar;C:\src\IdeaProjects\GOLD\extlib\commons-collections\jars\commons-collections-2.1.jar;C:\src\IdeaProjects\GOLD\extlib\commons-lang\jars\commons-lang-2.0.jar;C:\src\IdeaProjects\GOLD\extlib\ehcache\jars\ehcache-0.7.jar;C:\src\IdeaProjects\GOLD\extlib\GOLD\jars\abc-clio-1.0-SNAPSHOT.jar;C:\src\IdeaProjects\GOLD\extlib\GOLD\jars\helpxmlbeans-1.0-SNAPSHOT.jar;C:\src\IdeaProjects\GOLD\extlib\GOLD\jars\hitsxmlbeans-1.0-SNAPSHOT.jar;C:\src\IdeaProjects\GOLD\extlib\GOLD\jars\pregoldxmlbeans-1.0-SNAPSHOT.jar;C:\src\IdeaProjects\GOLD\extlib\GOLD\jars\productconfig-1.0-SNAPSHOT.jar;C:\src\IdeaProjects\GOLD\extlib\jfig\jars\jfig-1.2.jar;C:\src\IdeaProjects\GOLD\extlib\junit\jars\junit-3.8.1.jar;C:\src\IdeaProjects\GOLD\extlib\log4j\jars\log4j-1.2.8.jar;C:\src\IdeaProjects\GOLD\extlib\mockobjects\jars\mockobjects-0.9.1.jar;C:\src\IdeaProjects\GOLD\extlib\mockobjects\jars\mockobjects-jdk1.3-j2ee1.3-0.09.jar;C:\src\IdeaProjects\GOLD\extlib\xerces\jars\xercesImpl-2.5.jar;C:\src\IdeaProjects\GOLD\extlib\xerces\jars\xmlParserAPIs-2.2.jar;C:\src\IdeaProjects\GOLD\extlib\commons-logging\jars\commons-logging-1.0.3.jar;C:\src\IdeaProjects\GOLD\extlib\sybase\jars\jconn2-5.5.jar;C:\src\IdeaProjects\GOLD\extlib\xml-beans\jars\xbean-1.0.3.jar;C:\src\IdeaProjects\GOLD\extlib\xml-beans\jars\xbean_xpath-1.0.3.jar;C:\src\jaxen\target\jaxen-1.1-beta-4.jar;C:\apps\googleapi\googleapi.jar;C:\Ice-1.5.1\lib\Ice.jar;C:\tomcat-5.0.27\common\lib\commons-dbcp-1.2.1.jar;C:\tomcat-5.0.27\common\lib\commons-pool-1.2.jar;C:\IntelliJ-EAP\lib\idea_rt.jar com.intellij.rt.execution.application.AppMain com.XmlObjectTest
      Thread:Thread: [0]
      java.lang.IllegalStateException: Cursor has been disposed
      at org.apache.xmlbeans.impl.store.Cursor.checkDisposed(Cursor.java:116)
      at org.apache.xmlbeans.impl.store.Cursor.checkDisposed(Cursor.java:110)
      at org.apache.xmlbeans.impl.store.Cursor.toBookmark(Cursor.java:255)
      at org.apache.xmlbeans.XmlCursor$XmlBookmark.toBookmark(XmlCursor.java:1312)
      at org.apache.xmlbeans.impl.xpath.jaxen.XBeansNavigator.getChildAxisIterator(XBeansNavigator.java:387)
      at org.jaxen.expr.iter.IterableChildAxis.iterator(IterableChildAxis.java:79)
      at org.jaxen.expr.DefaultStep.axisIterator(DefaultStep.java:137)
      at org.jaxen.expr.DefaultNameStep.evaluate(DefaultNameStep.java:201)
      at org.jaxen.expr.DefaultLocationPath.evaluate(DefaultLocationPath.java:151)
      at org.jaxen.expr.DefaultXPathExpr.asList(DefaultXPathExpr.java:107)
      at org.jaxen.BaseXPath.selectNodesForContext(BaseXPath.java:715)
      at org.jaxen.BaseXPath.selectNodes(BaseXPath.java:244)
      at org.apache.xmlbeans.impl.xpath.jaxen.XBeansXPathAdv.selectNodes(XBeansXPathAdv.java:76)
      at org.apache.xmlbeans.impl.xpath.jaxen.XBeansXPathAdv.selectPath(XBeansXPathAdv.java:83)
      at org.apache.xmlbeans.impl.store.Path$JaxenPathImpl$JaxenPathEngine.next(Path.java:536)
      at org.apache.xmlbeans.impl.store.Cursor$Selections.setCursor(Cursor.java:3260)
      at org.apache.xmlbeans.impl.store.Cursor.selectPath(Cursor.java:2903)
      at org.apache.xmlbeans.impl.values.XmlObjectBase.selectPath(XmlObjectBase.java:396)
      at org.apache.xmlbeans.impl.values.XmlObjectBase.selectPath(XmlObjectBase.java:380)
      at com.XmlObjectTest.fetchDocumentTypeFromCitation(XmlObjectTest.java:101)
      at com.XmlObjectTest.runTest(XmlObjectTest.java:90)
      at com.XmlObjectTest.access$000(XmlObjectTest.java:37)
      at com.XmlObjectTest$TestThread.run(XmlObjectTest.java:76)
      Thread: [1] => documentType = Article
      Thread: [0] => documentType = null

      Process finished with exit code 0

      Test program:
      /**

      • XmlObjectTest.java
      • Version : GOLD 0.1
        *
      • Copyright 2004,
      • by The Gale Group
      • 27500 Drake Rd.
      • Farmington Hills, MI 48331-3535
      • Telephone (248) 699-4253
        *
      • This code is the sole property of The Gale Group and is protected by
      • copyright under the laws of the United States. This program is
      • confidential, proprietary, and a trade secret, not to be disclosed
      • without written authorization from The Gale Group. Any use,
      • duplication, or disclosure of this program by other than
      • The Gale Group and its assigned licensees is strictly forbidden by law.
        *
      • All rights reserved.
        */
        package com;

      import org.apache.xmlbeans.XmlObject;
      import org.apache.xmlbeans.XmlException;
      import org.apache.xmlbeans.impl.values.XmlObjectBase;

      import java.io.FileReader;
      import java.io.File;
      import java.io.FileNotFoundException;
      import java.io.IOException;

      /**

      • The <code>XmlObjectTest </code>
        *
      • @author Venkat Ramana Sonnathi (HTC Global Svc. Inc.)
      • @version 1.0
        */
        public class XmlObjectTest {

      public static void main(String[] args) throws XmlException, IOException, InterruptedException {

      for(int i=0 ; i < 2 ; ++i)

      { TestThread mythread = new TestThread("Thread: [" + i + "]"); mythread.start(); }

      }

      public static class TestThread extends Thread {
      /**

      • Allocates a new <code>Thread</code> object. This constructor has
      • the same effect as <code>Thread(null, null, name)</code>.
        *
      • @param name the name of the new thread.
      • @see Thread#Thread(ThreadGroup,
      • Runnable, String)
        */
        public TestThread(String name) { super(name); }

      /**

      • If this thread was constructed using a separate
      • <code>Runnable</code> run object, then that
      • <code>Runnable</code> object's <code>run</code> method is called;
      • otherwise, this method does nothing and returns.
      • <p/>
      • Subclasses of <code>Thread</code> should override this method.
        *
      • @see Thread#start()
      • @see Thread#stop()
      • @see Thread#Thread(ThreadGroup,
      • Runnable, String)
      • @see Runnable#run()
        */
        public void run() { XmlObjectTest.runTest(getName()); }

      }

      private static void runTest(String name) {
      XmlObject result = null;
      try

      { result = XmlObject.Factory.parse(new FileReader(new File("resultItem.xml"))); }

      catch (XmlException e)

      { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. }

      String documentType = fetchDocumentTypeFromCitation(result, "FIELD[@NAME='DT']");
      System.out.println(name + " => documentType = " + documentType);
      //To change body of created methods use File | Settings | File Templates.
      }

      private static String fetchDocumentTypeFromCitation(XmlObject xmlObject, String xpathForDocType) {

      try {
      XmlObject[] docTypeArr = null;
      if (xpathForDocType != null) {
      docTypeArr = xmlObject.selectPath("CB/CD/" + xpathForDocType);
      if (docTypeArr.length > 0)

      { return ((XmlObjectBase) docTypeArr[0]).getStringValue(); }

      }
      docTypeArr = xmlObject.selectPath("CB/CD/RECTYPE");
      String docType = (docTypeArr.length > 0) ? ((XmlObjectBase) docTypeArr[0]).getStringValue() : null;
      return docType;
      } catch (Exception e)

      { System.out.println("Thread:"+ Thread.currentThread().getName()); e.printStackTrace(); }

      return null;
      }

      }

      Sample xml file:
      <?xml version="1.0" encoding="UTF-8"?>
      <CB>
      <CI>1</CI>
      <CM>N</CM>
      <CV>N</CV>
      <CFT>N</CFT>
      <CEFT>N</CEFT>
      <CFA>N</CFA>
      <CFI>N</CFI>
      <CFEI>N</CFEI>
      <CEMAIL>N</CEMAIL>
      <L2H>B</L2H>
      <CFN>N</CFN>
      <CJ>7010</CJ>
      <CN>CX3411000020</CN>
      <RT>46</RT>
      <CP>X</CP>
      <CD>
      <RECTYPE>EBKS</RECTYPE>
      <VERSION>FMT BUILD G_1_00_00_006 10/30/2004</VERSION>
      <TABLE>gold_cita_ebks.fmt 09-Oct-2004</TABLE>
      <FIELD NAME="AL">Middle School</FIELD>
      <FIELD NAME="BA">0PHX</FIELD>
      <FIELD NAME="BE">Baker, Lawrence W.</FIELD>
      <FIELD NAME="BE">Hillstrom, Kevin</FIELD>
      <FIELD NAME="BE">Hillstrom, Laurie Collier</FIELD>
      <FIELD NAME="BE">Carnagie, Julie L.</FIELD>
      <FIELD NAME="BU">Lawrence W. Baker</FIELD>
      <FIELD NAME="BU">Kevin Hillstrom</FIELD>
      <FIELD NAME="BU">Laurie Collier Hillstrom</FIELD>
      <FIELD NAME="BU">Julie L. Carnagie</FIELD>
      <FIELD NAME="CB">French and Indian War</FIELD>
      <FIELD NAME="CG">
      <I>French and Indian War</I>
      . Lawrence W. Baker, Kevin Hillstrom, Laurie Collier Hillstrom, and Julie L. Carnagie, eds. Vol. 1. Detroit: U*X*L, 2003.
      </FIELD>
      <FIELD NAME="DT">Article</FIELD>
      <FIELD NAME="EB">0-7876-9158-5</FIELD>
      <FIELD NAME="EI">0787691585</FIELD>
      <FIELD NAME="FL">fiw_01_00020.xml</FIELD>
      <FIELD NAME="IB">0-7876-6560-6</FIELD>
      <FIELD NAME="IL">Yes</FIELD>
      <FIELD NAME="IP">00119</FIELD>
      <FIELD NAME="IX">UXL</FIELD>
      <FIELD NAME="LA">English</FIELD>
      <FIELD NAME="LP">Detroit</FIELD>
      <FIELD NAME="MG">bookitem</FIELD>
      <FIELD NAME="PB">U*X*L</FIELD>
      <FIELD NAME="PC">
      <b>King George II</b>
      . .
      </FIELD>
      <FIELD NAME="PC">
      <b>John Stuart, third earl of Bute</b>
      .
      <i>Reproduced by permission of</i>
      .
      </FIELD>
      <FIELD NAME="PC">
      <b>Lieutenant Colonel George Croghan</b>
      .
      <i>Reproduced by permission of</i>
      .
      </FIELD>
      <FIELD NAME="PF">Jan 1, 2003</FIELD>
      <FIELD NAME="SC">
      <I>French and Indian War</I>
      . Vol. 1. U*X*L, 2003.
      </FIELD>
      <FIELD NAME="SH">History</FIELD>
      <FIELD NAME="SO">French and Indian War</FIELD>
      <FIELD NAME="SV">0001</FIELD>
      <FIELD NAME="TB">French and Indian War |9999|2003|0787691585</FIELD>
      <FIELD NAME="TD">1760-62: The War Continues in Europe</FIELD>
      <FIELD NAME="TE">1760-62: The War Continues in Europe</FIELD>
      <FIELD NAME="TG">9</FIELD>
      <FIELD NAME="TY">Topic Overview</FIELD>
      <FIELD NAME="UZ">FIW</FIELD>
      <FIELD NAME="XZ">1760-62: The War Continues in Europe</FIELD>
      <FIELD NAME="YC">2003</FIELD>
      <FIELD NAME="ZA">fiw_01_00119-p.pdf</FIELD>
      <FIELD NAME="ZB">fiw_01_00127-p.pdf</FIELD>
      <FIELD NAME="ZZ">CX3411000020</FIELD>
      <FIELD NAME="GI">Yes</FIELD>
      </CD>
      </CB>

      Attachments

        1. resultItem.xml
          3 kB
          Venkat Sonnathi
        2. XmlObjectTest.java
          4 kB
          Venkat Sonnathi

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            vsonnathi Venkat Sonnathi
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment