Uploaded image for project: 'Maven Surefire'
  1. Maven Surefire
  2. SUREFIRE-951

Better handling of file.encoding system property

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.13
    • 2.15
    • None
    • Any environment in which the file encoding is distinct from ${project.build.sourceEncoding}.

    Description

      It appears that Surefire doesn't (correctly) set -Dfile.encoding=${project.build.sourceEncoding} prior to running the tests. As a result the JVM will derive file.encoding from the environment's file encoding. This affects the return value of java.nio.charset.Charset#defaultCharset(), which reads the file.encoding system property exactly once, and is invoked very early on. Concretely this means that the unit tests are unnecessarily platform dependent.

      Thus I have two requests:

      1. Make -Dfile.encoding=${project.build.sourceEncoding} the default. That is, the following configuration setting should be implied:
        <argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
        
      2. Extend the method org.apache.maven.plugin.surefire.SurefireProperties#verifyLegalSystemProperties(org.apache.maven.plugin.logging.Log) such that is warns about users attempting to set the file.encoding property through the systemPropertyVariables configuration setting. Like with java.library.path, this does not work.

      I have attached a sample project that demonstrates the issue (simply run `mvn test`). Please have a look at the comments I added to the POM. I have tested this sample project only on Linux, but a colleague has confirmed that an instance of this issue can also be recreated on Windows.

      TIA for looking into this!

      Attachments

        1. file-encoding-example.tbz
          1 kB
          Stephan Schroevers

        Issue Links

          Activity

            People

              tibordigana Tibor Digana
              stephan202 Stephan Schroevers
              Votes:
              1 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: