Axiom
  1. Axiom
  2. AXIOM-74

StAXUtils incorrectly assumes that XMLInputFactory and XMLOutputFactory instances are thread safe

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.8
    • Fix Version/s: 1.2.9
    • Component/s: None
    • Labels:
      None

      Description

      StAXUtil uses a single XMLInputFactory or XMLOutputFactory instance (per classloader). This means that it makes the assumption that these instances are thread safe. However, there is nothing in the StAX specs that guarantees that, and Sun's implementation in JDK 6 is not thread safe, at least with the default properties [1] [2].

      [1] http://www.java2s.com/Open-Source/Java-Document/6.0-JDK-Modules-com.sun/xml/com/sun/xml/internal/stream/XMLInputFactoryImpl.java.htm
      [2] http://www.java2s.com/Open-Source/Java-Document/6.0-JDK-Modules-com.sun/xml/com/sun/xml/internal/stream/XMLOutputFactoryImpl.java.htm

        Issue Links

          Activity

          Hide
          Andreas Veithen added a comment -

          Adding Woodstox to the classpath is sufficient. Anyway, for Axis2, it is highly recommended to use Woodstox.

          Show
          Andreas Veithen added a comment - Adding Woodstox to the classpath is sufficient. Anyway, for Axis2, it is highly recommended to use Woodstox.
          Hide
          Jeff Hoffman added a comment -

          Hello Andreas,

          I am so glad to finally find this thread--have been searching for Axis2 1.5.1 concurrency issues for a while now and struggling to solve a nagging issue in my application. I'm pretty confident this is the answer, so thank you!

          My question: do I need to use 1.2.9-SNAPSHOT to get this fix, or will Woodstox with 1.2.8 solve it?

          Thanks again,

          Jeff

          Show
          Jeff Hoffman added a comment - Hello Andreas, I am so glad to finally find this thread--have been searching for Axis2 1.5.1 concurrency issues for a while now and struggling to solve a nagging issue in my application. I'm pretty confident this is the answer, so thank you! My question: do I need to use 1.2.9-SNAPSHOT to get this fix, or will Woodstox with 1.2.8 solve it? Thanks again, Jeff
          Hide
          Ben Reif added a comment -

          Ok, I'll take a look. Thanks a lot for your help!

          Show
          Ben Reif added a comment - Ok, I'll take a look. Thanks a lot for your help!
          Hide
          Andreas Veithen added a comment -

          If there is a single StAX implementation (other than the one in the JRE in Java 6) in the classpath, then it will be used automatically. Only if there are multiple implementations in the classpath, you need to change system properties or property files. Have a look at the Javadoc of XMLInputFactory#newInstance for more information.

          Show
          Andreas Veithen added a comment - If there is a single StAX implementation (other than the one in the JRE in Java 6) in the classpath, then it will be used automatically. Only if there are multiple implementations in the classpath, you need to change system properties or property files. Have a look at the Javadoc of XMLInputFactory#newInstance for more information.
          Hide
          Ben Reif added a comment -

          Aside from down loading the jars and putting them in the classpath, do yo know how I go about changing out the StAX implementation? There isn't much on the Woodstox site. Is it just a VM system property that I set, or is there another file that I need to change to point to the Woodstox classes?

          Show
          Ben Reif added a comment - Aside from down loading the jars and putting them in the classpath, do yo know how I go about changing out the StAX implementation? There isn't much on the Woodstox site. Is it just a VM system property that I set, or is there another file that I need to change to point to the Woodstox classes?
          Hide
          Andreas Veithen added a comment -

          Ben,

          If you want to minimize risk and have a stable environment, then you should use Woodstox instead of SJSXP, as this eliminates the root cause of the issue.

          Show
          Andreas Veithen added a comment - Ben, If you want to minimize risk and have a stable environment, then you should use Woodstox instead of SJSXP, as this eliminates the root cause of the issue.
          Hide
          Ben Reif added a comment -

          Andreas,

          Thanks for the quick reply. I guess technically nothing is preventing us from using the 1.2.9-SNAPSHOT. We are using Axis2 1.4 (which came with Axiom 1.2.7) and it's really more of a question of risk and how stable the Axiom1.2.9-SNAPSHOT is and also if it is compatible with Axis2 1.4. Would you be able to provide any feedback on this?

          Thanks,
          Ben

          Show
          Ben Reif added a comment - Andreas, Thanks for the quick reply. I guess technically nothing is preventing us from using the 1.2.9-SNAPSHOT. We are using Axis2 1.4 (which came with Axiom 1.2.7) and it's really more of a question of risk and how stable the Axiom1.2.9-SNAPSHOT is and also if it is compatible with Axis2 1.4. Would you be able to provide any feedback on this? Thanks, Ben
          Hide
          Andreas Veithen added a comment -

          Ben,

          There have been too many changes between 1.2.7 and HEAD in the part of the code affected by this fix (for example, the entire StAX dialect mechanism is new in 1.2.9), so that backporting the change using individual patches is not feasible. What is actually preventing you from using 1.2.9-SNAPSHOT?

          Andreas

          Show
          Andreas Veithen added a comment - Ben, There have been too many changes between 1.2.7 and HEAD in the part of the code affected by this fix (for example, the entire StAX dialect mechanism is new in 1.2.9), so that backporting the change using individual patches is not feasible. What is actually preventing you from using 1.2.9-SNAPSHOT? Andreas
          Hide
          Ben Reif added a comment - - edited

          Andreas,

          We are using Axiom 1.2.7 and wanted to patch in this fix. Can you let me know what changes that you made and how I can patch them in? If I go to the Subversion Commits tab, can I just put in the changes under revision #797814, or do I also need the ones from #823973 and #823978 as well?

          Thanks

          Show
          Ben Reif added a comment - - edited Andreas, We are using Axiom 1.2.7 and wanted to patch in this fix. Can you let me know what changes that you made and how I can patch them in? If I go to the Subversion Commits tab, can I just put in the changes under revision #797814, or do I also need the ones from #823973 and #823978 as well? Thanks
          Hide
          Andreas Veithen added a comment -

          I noticed that the JRE on people.apache.org (1.6.0_07) has a version of SJSXP with the same issue. I have implemented a fix that detects this issue and applies a workaround.

          Show
          Andreas Veithen added a comment - I noticed that the JRE on people.apache.org (1.6.0_07) has a version of SJSXP with the same issue. I have implemented a fix that detects this issue and applies a workaround.
          Hide
          Andreas Veithen added a comment -

          Anyone using Axiom together with a broken StAX parser implementation may obviously run into issues. As your case shows, this applies in particular to early versions of Sun's 1.6 JRE IF the user chooses to exclude the Woodstox dependency (which is the recommended StAX parser implementation for Axiom).

          I was able to reproduce the issue with 1.6.0.5. Once I find a proper way to distinguish broken versions of SJSXP, I will update the StAX dialect detector to apply a workaround for the thread safety issue. However, since I only have access to that particular JRE version at work and not at home, this might take some time.

          Show
          Andreas Veithen added a comment - Anyone using Axiom together with a broken StAX parser implementation may obviously run into issues. As your case shows, this applies in particular to early versions of Sun's 1.6 JRE IF the user chooses to exclude the Woodstox dependency (which is the recommended StAX parser implementation for Axiom). I was able to reproduce the issue with 1.6.0.5. Once I find a proper way to distinguish broken versions of SJSXP, I will update the StAX dialect detector to apply a workaround for the thread safety issue. However, since I only have access to that particular JRE version at work and not at home, this might take some time.
          Hide
          Aaron McIver added a comment -

          Any luck? Or is it simply the fact that I need to update the JDK? And furthermore would it imply that anyone running 1.6.0.5 for instance out in the field via the JRE...will run into this same issue?

          Show
          Aaron McIver added a comment - Any luck? Or is it simply the fact that I need to update the JDK? And furthermore would it imply that anyone running 1.6.0.5 for instance out in the field via the JRE...will run into this same issue?
          Hide
          Andreas Veithen added a comment -

          1.6.0.5 is quite old. It could be that you are seeing the issue that the SJSXP project fixed in [1]. This issue implies that even after setting "reuse-instance" to false on the XMLOutputFactory, the factory is still not thread safe. I will see if I can find a 1.6.0.5 JDK somewhere to check this.

          [1] https://sjsxp.dev.java.net/source/browse/sjsxp/zephyr/src/com/sun/xml/stream/ZephyrWriterFactory.java?rev=1.8&r1=1.4&r2=1.5

          Show
          Andreas Veithen added a comment - 1.6.0.5 is quite old. It could be that you are seeing the issue that the SJSXP project fixed in [1] . This issue implies that even after setting "reuse-instance" to false on the XMLOutputFactory, the factory is still not thread safe. I will see if I can find a 1.6.0.5 JDK somewhere to check this. [1] https://sjsxp.dev.java.net/source/browse/sjsxp/zephyr/src/com/sun/xml/stream/ZephyrWriterFactory.java?rev=1.8&r1=1.4&r2=1.5
          Hide
          Aaron McIver added a comment - - edited

          Test information:

          -------------------------------------------------------------------------------
          Test set: ParserTest
          -------------------------------------------------------------------------------
          Tests run: 3500, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 50.548 sec <<< FAILURE!
          testCreateXMLStreamWriterIsThreadSafe(org.apache.axiom.om.util.StAXUtilsTest) Time elapsed: 0.047 sec <<< FAILURE!
          junit.framework.ComparisonFailure: expected:<[<root>951</root>]> but was:<[]>
          at junit.framework.Assert.assertEquals(Assert.java:81)
          at junit.framework.Assert.assertEquals(Assert.java:87)
          at org.apache.axiom.om.util.StAXUtilsTest$3.execute(StAXUtilsTest.java:104)
          at org.apache.axiom.om.util.StAXUtilsTest$1.run(StAXUtilsTest.java:47)
          at java.lang.Thread.run(Thread.java:619)

          Dialect information:

          00067: Oct 5, 2009 8:23:24 AM org.apache.axiom.util.stax.dialect.StAXDialectDetector detectDialect
          00068: INFO: Detected StAX dialect: Woodstox
          00069: Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.188 sec
           
          00153: Oct 5, 2009 8:23:38 AM org.apache.axiom.util.stax.dialect.StAXDialectDetector detectDialect
          00154: INFO: Detected StAX dialect: Woodstox
          00155: Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.5 sec
           
          00243: Oct 5, 2009 8:23:57 AM org.apache.axiom.util.stax.dialect.StAXDialectDetector detectDialect
          00244: INFO: Detected StAX dialect: Woodstox
          00245: Tests run: 9, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.093 sec
           
          00336: Oct 5, 2009 8:24:10 AM org.apache.axiom.util.stax.dialect.StAXDialectDetector detectDialect
          00337: INFO: Detected StAX dialect: Woodstox
          00338: Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.36 sec
           
          00400: Oct 5, 2009 8:24:17 AM org.apache.axiom.util.stax.dialect.StAXDialectDetector detectDialect
          00401: INFO: Detected StAX dialect: Woodstox
          00402: Tests run: 17, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.266 sec
           
          00717: Oct 5, 2009 8:24:50 AM org.apache.axiom.util.stax.dialect.StAXDialectDetector detectDialect
          00718: INFO: Detected StAX dialect: SJSXP
          00719: Oct 5, 2009 8:24:52 AM org.apache.axiom.util.blob.OverflowBlob finalize
           
          00737: Oct 5, 2009 8:25:13 AM org.apache.axiom.util.stax.dialect.StAXDialectDetector detectDialect
          00738: INFO: Detected StAX dialect: SJSXP
          00739: Oct 5, 2009 8:25:15 AM org.apache.axiom.util.blob.OverflowBlob finalize
           
          00757: Oct 5, 2009 8:25:33 AM org.apache.axiom.util.stax.dialect.StAXDialectDetector detectDialect
          00758: INFO: Detected StAX dialect: BEA
          00759: Oct 5, 2009 8:25:34 AM org.apache.axiom.util.blob.OverflowBlob finalize
           
          00777: Oct 5, 2009 8:25:44 AM org.apache.axiom.util.stax.dialect.StAXDialectDetector detectDialect
          00778: INFO: Detected StAX dialect: Woodstox
          00779: Oct 5, 2009 8:25:45 AM org.apache.axiom.util.blob.OverflowBlob finalize
           

          The below 2 lines appeared in the console but did not make it to the output file...for what that is worth...performed a mvn clean followed by a mvn install > install.txt

          The current artifact axiom-osgi-run-1.2.9-SNAPSHOT.jar is not a valid bundle
          [INFO] Detected StAX dialect: SJSXP

          Java information:

          -JDK = Sun 1.6.5
          -JRE = Sun 1.6.13
          -JAVA_HOME = JDK

          Show
          Aaron McIver added a comment - - edited Test information: ------------------------------------------------------------------------------- Test set: ParserTest ------------------------------------------------------------------------------- Tests run: 3500, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 50.548 sec <<< FAILURE! testCreateXMLStreamWriterIsThreadSafe(org.apache.axiom.om.util.StAXUtilsTest) Time elapsed: 0.047 sec <<< FAILURE! junit.framework.ComparisonFailure: expected:< [<root>951</root>] > but was:<[]> at junit.framework.Assert.assertEquals(Assert.java:81) at junit.framework.Assert.assertEquals(Assert.java:87) at org.apache.axiom.om.util.StAXUtilsTest$3.execute(StAXUtilsTest.java:104) at org.apache.axiom.om.util.StAXUtilsTest$1.run(StAXUtilsTest.java:47) at java.lang.Thread.run(Thread.java:619) Dialect information: 00067: Oct 5, 2009 8:23:24 AM org.apache.axiom.util.stax.dialect.StAXDialectDetector detectDialect 00068: INFO: Detected StAX dialect: Woodstox 00069: Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.188 sec   00153: Oct 5, 2009 8:23:38 AM org.apache.axiom.util.stax.dialect.StAXDialectDetector detectDialect 00154: INFO: Detected StAX dialect: Woodstox 00155: Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.5 sec   00243: Oct 5, 2009 8:23:57 AM org.apache.axiom.util.stax.dialect.StAXDialectDetector detectDialect 00244: INFO: Detected StAX dialect: Woodstox 00245: Tests run: 9, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.093 sec   00336: Oct 5, 2009 8:24:10 AM org.apache.axiom.util.stax.dialect.StAXDialectDetector detectDialect 00337: INFO: Detected StAX dialect: Woodstox 00338: Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.36 sec   00400: Oct 5, 2009 8:24:17 AM org.apache.axiom.util.stax.dialect.StAXDialectDetector detectDialect 00401: INFO: Detected StAX dialect: Woodstox 00402: Tests run: 17, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.266 sec   00717: Oct 5, 2009 8:24:50 AM org.apache.axiom.util.stax.dialect.StAXDialectDetector detectDialect 00718: INFO: Detected StAX dialect: SJSXP 00719: Oct 5, 2009 8:24:52 AM org.apache.axiom.util.blob.OverflowBlob finalize   00737: Oct 5, 2009 8:25:13 AM org.apache.axiom.util.stax.dialect.StAXDialectDetector detectDialect 00738: INFO: Detected StAX dialect: SJSXP 00739: Oct 5, 2009 8:25:15 AM org.apache.axiom.util.blob.OverflowBlob finalize   00757: Oct 5, 2009 8:25:33 AM org.apache.axiom.util.stax.dialect.StAXDialectDetector detectDialect 00758: INFO: Detected StAX dialect: BEA 00759: Oct 5, 2009 8:25:34 AM org.apache.axiom.util.blob.OverflowBlob finalize   00777: Oct 5, 2009 8:25:44 AM org.apache.axiom.util.stax.dialect.StAXDialectDetector detectDialect 00778: INFO: Detected StAX dialect: Woodstox 00779: Oct 5, 2009 8:25:45 AM org.apache.axiom.util.blob.OverflowBlob finalize   The below 2 lines appeared in the console but did not make it to the output file...for what that is worth...performed a mvn clean followed by a mvn install > install.txt The current artifact axiom-osgi-run-1.2.9-SNAPSHOT.jar is not a valid bundle [INFO] Detected StAX dialect: SJSXP Java information: -JDK = Sun 1.6.5 -JRE = Sun 1.6.13 -JAVA_HOME = JDK
          Hide
          Andreas Veithen added a comment -

          Axiom now has a mechanism that detects the StAX implementation and that (among other things) makes the factories thread safe. This however only works if it correctly detects the StAX "dialect", which is probably what fails in your case.

          The test you mention is executed several times during the build: once in axiom-api and several times in axiom-parser-tests, using different StAX implementations. One execution of this test in axiom-parser-tests is against the StAX implementation that is part of the JRE (on Java >= 1.6). It is probably this execution that fails. Can you please provide the following additional information:

          • The tests in axiom-parser-tests output several lines starting with "INFO: Detected StAX dialect". Can you please post these messages?
          • What JRE (vendor and version) do you use? Do you know which StAX parser is shipped with that JRE?
          Show
          Andreas Veithen added a comment - Axiom now has a mechanism that detects the StAX implementation and that (among other things) makes the factories thread safe. This however only works if it correctly detects the StAX "dialect", which is probably what fails in your case. The test you mention is executed several times during the build: once in axiom-api and several times in axiom-parser-tests, using different StAX implementations. One execution of this test in axiom-parser-tests is against the StAX implementation that is part of the JRE (on Java >= 1.6). It is probably this execution that fails. Can you please provide the following additional information: The tests in axiom-parser-tests output several lines starting with "INFO: Detected StAX dialect". Can you please post these messages? What JRE (vendor and version) do you use? Do you know which StAX parser is shipped with that JRE?
          Hide
          Aaron McIver added a comment -

          I just pulled down the source...mvn install...

          Failed tests:
          testCreateXMLStreamWriterIsThreadSafe(org.apache.axiom.om.util.StAXUtilsTest)

          Which seems to have happened as recent as September...is this really fixed?

          Show
          Aaron McIver added a comment - I just pulled down the source...mvn install... Failed tests: testCreateXMLStreamWriterIsThreadSafe(org.apache.axiom.om.util.StAXUtilsTest) Which seems to have happened as recent as September...is this really fixed?
          Show
          Andreas Veithen added a comment - See also https://sjsxp.dev.java.net/issues/show_bug.cgi?id=4

            People

            • Assignee:
              Andreas Veithen
              Reporter:
              Andreas Veithen
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development