Uploaded image for project: 'ShrinkWrap Resolvers'
  1. ShrinkWrap Resolvers
  2. SHRINKRES-217

FileUtil.fileFromClassLoaderResource() creates non-unique temporary file

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 2.2.0-beta-2
    • 2.0.2
    • maven
    • None

    Description

      org.jboss.shrinkwrap.resolver.impl.maven.util.FileUtil copies a classpath file to the system temp directory (defined by java.io.tmpdir) to be able to work with it as a plain file.

      The problem is that the file name is used as is.
      Now imagine multiple maven-surefire processes running Tests using the same classpath resource. They all and up trying to write a file with the same name in a (more or less) global temporary directory.

      Because of this we have seen multiple build failures on or Jenkins CI machine which uses -T... and -DforkCount=... liberally like this one:

      Caused by: org.jboss.shrinkwrap.resolver.api.InvalidConfigurationFileException: Found 1 problems while building POM model from /tmp/someproject-main-continuous-1.1.1/META-INF-maven-com.somecompany.someproject-middleware-common-test-pom.xml
      1/ [FATAL] Non-readable POM /tmp/someproject-main-continuous-1.1.1/META-INF-maven-com.somecompany.someproject-middleware-common-test-pom.xml: no more data available - expected end tags </version></dependency></dependencies></project> to close start tag <version> from line 75 and start tag <dependency> from line 77 and start tag <dependencies> from line 48 and start tag <project> from line 2, parser stopped on TEXT seen ...<dependency>\n            <gro... @78:17 @ /tmp/someproject-main-continuous-1.1.1/META-INF-maven-com.somecompany.someproject-middleware-common-test-pom.xml

      Solution:
      Instead of:

      File localResource = new File(tmpDir, resourceName.replace("/", "-").replace("\\", "-").replace(File.pathSeparator, "-").replaceAll("\\s", "-"));

      use:
      File localResource = java.io.File.createTempFile(...)
      which generates a file name that will most likely be "unique" for a certain time.

      Attachments

        Activity

          People

            kpiwko Karel Piwko
            falko.modler@t-systems.com Falko Modler (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: