Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XSLDocument is not thread-safe #185

Closed
mximp opened this issue Oct 18, 2022 · 14 comments
Closed

XSLDocument is not thread-safe #185

mximp opened this issue Oct 18, 2022 · 14 comments
Assignees

Comments

@mximp
Copy link

mximp commented Oct 18, 2022

The following code fails:

      final XSL xsl =
          new XSLDocument(
              this.getClass().getResourceAsStream("/org/eolang/parser/optimize/globals-to-abstracts.xsl")
          ).with(new ClasspathSources());
      final List<Callable<Object>> tasks = new ArrayList<>(10);
      final List<Exception> exceptions = Collections.synchronizedList(new ArrayList<>(0));
      IntStream.range(1, 11)
          .forEach( i ->
              tasks.add(Executors.callable( () -> {
                  try {
                      xsl.transform(
                          new XMLDocument(
                              Paths.get(
                                  this.getClass().getResource("/valid-xml-in-classpath.xml").toURI())));
                  } catch (Exception e) {
                      exceptions.add(e);
                  }
              }))
          );
      do {
          Executors.newFixedThreadPool(10).invokeAll(tasks);
      } while (exceptions.isEmpty());
      if (!exceptions.isEmpty()) {
          exceptions.forEach(Throwable::printStackTrace);
          throw new IllegalStateException(exceptions.toString());
      }

Exception thrown:

java.lang.IllegalArgumentException: Failed to transform by net.sf.saxon.jaxp.TransformerImpl: [] (org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.; SystemID: file:///; Line#: 54; Column#: 35)
	at com.jcabi.xml.XSLDocument.transformInto(XSLDocument.java:411)
	at com.jcabi.xml.XSLDocument.transform(XSLDocument.java:371)
	at org.eolang.maven.OptimizeMojoTest.lambda$testTemp$1(OptimizeMojoTest.java:281)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: net.sf.saxon.trans.XPathException: org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.
	at net.sf.saxon.dom.DOMWriter.startElement(DOMWriter.java:192)
	at net.sf.saxon.event.ProxyReceiver.startElement(ProxyReceiver.java:140)
	at net.sf.saxon.event.SequenceNormalizer.startElement(SequenceNormalizer.java:85)
	at net.sf.saxon.event.RegularSequenceChecker.startElement(RegularSequenceChecker.java:380)
	at net.sf.saxon.event.ComplexContentOutputter.startContent(ComplexContentOutputter.java:779)
	at net.sf.saxon.event.ComplexContentOutputter.characters(ComplexContentOutputter.java:269)
	at net.sf.saxon.expr.instruct.Copy.processLeavingTail(Copy.java:453)
	at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:392)
	at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:551)
	at net.sf.saxon.expr.instruct.ApplyTemplates.apply(ApplyTemplates.java:360)
	at net.sf.saxon.expr.instruct.ApplyTemplates.process(ApplyTemplates.java:294)
	at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:357)
	at net.sf.saxon.expr.instruct.Copy.processLeavingTail(Copy.java:437)
	at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:392)
	at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:551)
	at net.sf.saxon.trans.rules.TextOnlyCopyRuleSet.process(TextOnlyCopyRuleSet.java:72)
	at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:524)
	at net.sf.saxon.trans.XsltController.applyTemplates(XsltController.java:685)
	at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(AbstractXsltTransformer.java:422)
	at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:355)
	at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:75)
	at com.jcabi.xml.XSLDocument.transformInto(XSLDocument.java:408)
	... 7 more
Caused by: org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.
	at java.xml/com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.insertBefore(CoreDocumentImpl.java:439)
	at java.xml/com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(NodeImpl.java:230)
	at net.sf.saxon.dom.DOMWriter.startElement(DOMWriter.java:157)
	... 28 more
@0crat
Copy link

0crat commented Oct 18, 2022

@yegor256/z everybody who has role DEV is banned at #185; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)

@0crat
Copy link

0crat commented Oct 23, 2022

@yegor256/z everybody who has role DEV is banned at #185; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)

@0crat
Copy link

0crat commented Oct 28, 2022

@yegor256/z everybody who has role DEV is banned at #185; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)

@0crat
Copy link

0crat commented Nov 2, 2022

@yegor256/z everybody who has role DEV is banned at #185; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)

@yegor256 yegor256 self-assigned this Nov 3, 2022
yegor256 added a commit that referenced this issue Nov 3, 2022
@yegor256
Copy link
Member

yegor256 commented Nov 3, 2022

@mximp I added a test in 614eb9a, but it doesn't find a bug. Are you sure there is a problem in jcabi-xml?

yegor256 added a commit that referenced this issue Nov 3, 2022
@mximp
Copy link
Author

mximp commented Nov 3, 2022

@yegor256 your test runs only once. This concurrent issue is not stable, hence in my version I added loop until exception is thrown. I checked your test with multiple executions and it resulted in the same error:

final XSL xsl = new XSLDocument(
            this.getClass().getResourceAsStream("/org/eolang/parser/xttool/transform.xsl")
        ).with(new ClasspathSources());
        final XML xml = new XMLDocument(
            this.getClass().getResourceAsStream("/org/eolang/parser/xttool/input.xml")
        );
        do {
            final AtomicInteger done = new AtomicInteger(0);
            final CountDownLatch latch = new CountDownLatch(1);
            final int total = 10;
            final ExecutorService exec = Executors.newFixedThreadPool(total);
            for (int task = 0; task < 10; ++task) {
                exec.submit(
                    () -> {
                        latch.await();
                        try {
                            xsl.transform(xml);
                        } catch (final Exception ex) {
                            ex.printStackTrace();
                        }
                        done.incrementAndGet();
                        return 0;
                    }
                );
            }
            latch.countDown();
            exec.shutdown();
            exec.awaitTermination(1L, TimeUnit.MINUTES);
            MatcherAssert.assertThat(done.get(), Matchers.equalTo(total));
        } while (true);

yegor256 added a commit that referenced this issue Nov 3, 2022
@yegor256
Copy link
Member

yegor256 commented Nov 3, 2022

@rultor release, tag is 0.25.5

@rultor
Copy link
Contributor

rultor commented Nov 3, 2022

@rultor release, tag is 0.25.5

@yegor256 OK, I will release it now. Please check the progress here

@rultor
Copy link
Contributor

rultor commented Nov 3, 2022

@rultor release, tag is 0.25.5

@mximp @yegor256 Oops, I failed. You can see the full log here (spent 10min)

javadoc: warning - The code being documented uses packages in the unnamed module, but the packages defined in https://docs.oracle.com/en/java/javase/14/docs/api/ are in named modules.
javadoc: warning - The code being documented uses packages in the unnamed module, but the packages defined in https://docs.oracle.com/en/java/javase/14/docs/api/ are in named modules.
javadoc: warning - The code being documented uses packages in the unnamed module, but the packages defined in https://docs.oracle.com/en/java/javase/14/docs/api/ are in named modules.
javadoc: warning - The code being documented uses packages in the unnamed module, but the packages defined in https://docs.oracle.com/en/java/javase/14/docs/api/ are in named modules.
javadoc: warning - The code being documented uses packages in the unnamed module, but the packages defined in https://docs.oracle.com/en/java/javase/14/docs/api/ are in named modules.
javadoc: warning - The code being documented uses packages in the unnamed module, but the packages defined in https://docs.oracle.com/en/java/javase/14/docs/api/ are in named modules.
javadoc: warning - The code being documented uses packages in the unnamed module, but the packages defined in https://docs.oracle.com/en/java/javase/14/docs/api/ are in named modules.
javadoc: warning - The code being documented uses packages in the unnamed module, but the packages defined in https://docs.oracle.com/en/java/javase/14/docs/api/ are in named modules.
javadoc: warning - The code being documented uses packages in the unnamed module, but the packages defined in https://docs.oracle.com/en/java/javase/14/docs/api/ are in named modules.
javadoc: warning - The code being documented uses packages in the unnamed module, but the packages defined in https://docs.oracle.com/en/java/javase/14/docs/api/ are in named modules.
javadoc: warning - The code being documented uses packages in the unnamed module, but the packages defined in https://docs.oracle.com/en/java/javase/14/docs/api/ are in named modules.
javadoc: warning - The code being documented uses packages in the unnamed module, but the packages defined in https://docs.oracle.com/en/java/javase/14/docs/api/ are in named modules.
javadoc: warning - The code being documented uses packages in the unnamed module, but the packages defined in https://docs.oracle.com/en/java/javase/14/docs/api/ are in named modules.
javadoc: warning - The code being documented uses packages in the unnamed module, but the packages defined in https://docs.oracle.com/en/java/javase/14/docs/api/ are in named modules.
javadoc: warning - The code being documented uses packages in the unnamed module, but the packages defined in https://docs.oracle.com/en/java/javase/14/docs/api/ are in named modules.
javadoc: error - Error fetching URL: https://xerces.apache.org/xml-commons/

Command line was: /usr/lib/jvm/java-11-openjdk-amd64/bin/javadoc @options @argfile

Refer to the generated Javadoc files in '/home/r/repo/target/site/apidocs-0.25.5' dir.

    at org.apache.maven.plugins.javadoc.AbstractJavadocMojo.doExecuteJavadocCommandLine (AbstractJavadocMojo.java:6092)
    at org.apache.maven.plugins.javadoc.AbstractJavadocMojo.executeJavadocCommandLine (AbstractJavadocMojo.java:5968)
    at org.apache.maven.plugins.javadoc.AbstractJavadocMojo.executeReport (AbstractJavadocMojo.java:2277)
    at org.apache.maven.plugins.javadoc.JavadocReport.generate (JavadocReport.java:150)
    at org.apache.maven.plugins.site.render.ReportDocumentRenderer.renderDocument (ReportDocumentRenderer.java:226)
    at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.render (DefaultSiteRenderer.java:348)
    at org.apache.maven.plugins.site.render.SiteMojo.renderLocale (SiteMojo.java:194)
    at org.apache.maven.plugins.site.render.SiteMojo.execute (SiteMojo.java:143)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:370)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
\u001b[0m\u001b[0mcontainer 7030682a92a7b14d72c9b1c7bdad898b85decf4dcf3864b95464cbee2505468c is dead
Thu 03 Nov 2022 10:49:47 AM CET

@yegor256
Copy link
Member

yegor256 commented Nov 3, 2022

@mximp it's released as 0.25.5

@mximp
Copy link
Author

mximp commented Nov 3, 2022

@yegor256 I guess it's not due to exception above. Also I don't see relevant tag in the repo.

@yegor256
Copy link
Member

yegor256 commented Nov 3, 2022

@mximp it was released, but site publishing failed. See https://repo.maven.apache.org/maven2/com/jcabi/jcabi-xml/

@mximp
Copy link
Author

mximp commented Nov 3, 2022

@yegor256 got it. thanks

@0crat
Copy link

0crat commented Nov 3, 2022

Job gh:jcabi/jcabi-xml#185 is not assigned, can't get performer

@0crat 0crat removed the 0crat/scope label Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants