[ 
https://issues.apache.org/jira/browse/MNG-6239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17240733#comment-17240733
 ] 

Guillaume Nodet commented on MNG-6239:
--------------------------------------

There is a misunderstanding here.

The standard streams should always be in auto flush mode, as that's the case by 
default in the JVM.  In older Jansi versions, this was not the case, so that 
should be fixed with 2.0.x.

However, the auto-flush of the {{PrintStream}}s only kicks in when a newline is 
printed somehow.  So {{println(String)}} will auto-flush, but {{print(String)}} 
and {{printf(String,Object...)}} won't, unless there's a newline, and that's 
the expected behaviour according to the {{PrintStream}} javadoc.  

This means that with the code in the attached zip below
{code:java}
        System.err.println("err.println");
        System.out.println("out.println");
        System.err.print("err.print");
        System.err.printf("err.printf");
        System.out.print("out.print");
        System.out.printf("out.printf");
        new BufferedReader(new InputStreamReader(System.in)).readLine(); {code}
the expected behaviour is
{code:java}
err.println
out.println{code}

It can be different, as no auto flush does not mean the characters won't be 
printed at all, rather than they may not be printed.

So the actual check is to modify the code to
{code:java}
        System.err.println("err.println");
        System.out.println("out.println");
        System.err.print("err.print");
        System.err.printf("err.printf");
        System.err.flush();
        System.out.print("out.print");
        System.out.printf("out.printf");
        System.out.flush();
        new BufferedReader(new InputStreamReader(System.in)).readLine(); {code}
the expected behaviour is
{code:java}
err.println
out.println
err.printerr.printfout.printout.printf{code}

I think any assumption beyond that is pointless.

> jansi messes up System.err and System.out
> -----------------------------------------
>
>                 Key: MNG-6239
>                 URL: https://issues.apache.org/jira/browse/MNG-6239
>             Project: Maven
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.5.0
>         Environment: Java 1.8.0_131, Ubuntu 17.04
>            Reporter: Simone Bordet
>            Priority: Minor
>         Attachments: mvn-jansi.tgz
>
>
> I use the Maven Exec Plugin to run a class that asks for interactive input 
> from the user. This was working in 3.3.9, but does not work in 3.5.0.
> Anything printed on {{System.err}} or {{System.out}} without a newline is not 
> printed immediately on the terminal window.
> Example:
> {code:java}
> BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
> System.err.printf("listen port: ");
> String value = console.readLine().trim();
> {code}
> The example above would not print {{listen port:}} on the terminal.
> Attached you can find a project that reproduces this issue.
> Unpack the project and then run:
> {noformat}
> $ mvn install && mvn exec:exec
> {noformat}
> The expected output of the reproducer would be:
> {noformat}
> err.println
> out.println
> err.printerr.printfout.printout.printf
> {noformat}
> instead I get:
> {noformat}
> err.println
> out.println
> {noformat}
> Removing {{jansi-1.13.jar}} from {{$MAVEN/lib/}} fixes the issue.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to