jtreg adds additional backslashes in Strings that are written to System.out/err?

Jaikiran Pai jai.forums2013 at gmail.com
Sun Aug 29 13:24:17 UTC 2021


Please consider this trivial Java code which prints to System.out:

public class FooTest {
     public static void main(final String[] args) throws Exception {
         final String m = "hello \\ world";
         System.out.println("Message is " + m);
     }
}

When you run this as Java code using the "java" command, the output that 
gets printed is (as expected):

Message is hello \ world

Now, if I convert this Java code a jtreg test as follows (without any 
code change, just adding jtreg tags):

/**
  * @test
  * @run main FooTest
  */
public class FooTest {
     public static void main(final String[] args) throws Exception {
         final String m = "hello \\ world";
         System.out.println("Message is " + m);
     }
}

Running it as a jtreg test, generates a report which has the System.out 
section that is:

----------System.out:(1/26)*----------
Message is hello \\ world

Notice the unexpected additional backslash in that output. Is this 
intentional?

In a non-trivial test case, that I was working on, it took me a (long) 
while to figure out that it was jtreg which was adding the additional 
backslash in the output and it wasn't my test case that had something wrong.

For reference, jtreg -version gives:

jtreg -version
jtreg 6-dev+0
Installed in /jtreg/build/images/jtreg/lib/jtreg.jar
Running on platform version 1.8.0_265 from 
/adoptopenjdk-8.jdk/Contents/Home/jre.
Built with Java(TM) 2 SDK, Version 1.8.0_265-b01 on June 27, 2021.
Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
Use is subject to license terms.
JT Harness, version 6.0 ea b14 (June 27, 2021)
JCov 3.0-2
Java Assembler Tools, version 7.0 ea b09 (June 27, 2021)
TestNG (testng.jar): version 7.3.0
TestNG (jcommander.jar): version unknown
TestNG (guice.jar): version 4.2.3
JUnit (junit.jar): version 4.13.2
JUnit (hamcrest.jar): version 2.2

-Jaikiran






More information about the jtreg-use mailing list