RFR: JDK-8031482: Some jcmd commands generate output with \n as a line separator instead of \r\n on Windows

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

RFR: JDK-8031482: Some jcmd commands generate output with \n as a line separator instead of \r\n on Windows

Gary Adams-3
Here's a simple fix to the split pattern when output lines are using
mixed line
separators in the same outputstream . e.g. split("\r\n|\n")

   Issue: https://bugs.openjdk.java.net/browse/JDK-8031482
   Webrev: http://cr.openjdk.java.net/~gadams/JDK-8031482

testing in progress ...
Reply | Threaded
Open this post in threaded view
|

Re: RFR: JDK-8031482: Some jcmd commands generate output with \n as a line separator instead of \r\n on Windows

Chris Plummer
Hi Gary,

I'm sure that fixes the problem, although there's no longer any platform
abstraction of what a newline is. Theoretically there could be a
platform for which it won't work, but I'm not so sure we really care
about theoreticals here, since it is just for testing purposes and
solves the issue on the platforms we know of. So thumbs up.

Chris

On 1/11/18 8:28 AM, Gary Adams wrote:
> Here's a simple fix to the split pattern when output lines are using
> mixed line
> separators in the same outputstream . e.g. split("\r\n|\n")
>
>   Issue: https://bugs.openjdk.java.net/browse/JDK-8031482
>   Webrev: http://cr.openjdk.java.net/~gadams/JDK-8031482
>
> testing in progress ...



Reply | Threaded
Open this post in threaded view
|

Re: RFR: JDK-8031482: Some jcmd commands generate output with \n as a line separator instead of \r\n on Windows

Gary Adams-3
Webrev url correction ...

On 1/11/18, 11:40 AM, Chris Plummer wrote:

> Hi Gary,
>
> I'm sure that fixes the problem, although there's no longer any
> platform abstraction of what a newline is. Theoretically there could
> be a platform for which it won't work, but I'm not so sure we really
> care about theoreticals here, since it is just for testing purposes
> and solves the issue on the platforms we know of. So thumbs up.
>
> Chris
>
> On 1/11/18 8:28 AM, Gary Adams wrote:
>> Here's a simple fix to the split pattern when output lines are using
>> mixed line
>> separators in the same outputstream . e.g. split("\r\n|\n")
>>
>>   Issue: https://bugs.openjdk.java.net/browse/JDK-8031482
>>   Webrev: http://cr.openjdk.java.net/~gadams/8031482
>>
>> testing in progress ...
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: RFR: JDK-8031482: Some jcmd commands generate output with \n as a line separator instead of \r\n on Windows

serguei.spitsyn@oracle.com
Hi Gary,

Looks Okay to me.

Thanks,
Serguei


On 1/11/18 09:04, Gary Adams wrote:

> Webrev url correction ...
>
> On 1/11/18, 11:40 AM, Chris Plummer wrote:
>> Hi Gary,
>>
>> I'm sure that fixes the problem, although there's no longer any
>> platform abstraction of what a newline is. Theoretically there could
>> be a platform for which it won't work, but I'm not so sure we really
>> care about theoreticals here, since it is just for testing purposes
>> and solves the issue on the platforms we know of. So thumbs up.
>>
>> Chris
>>
>> On 1/11/18 8:28 AM, Gary Adams wrote:
>>> Here's a simple fix to the split pattern when output lines are using
>>> mixed line
>>> separators in the same outputstream . e.g. split("\r\n|\n")
>>>
>>>   Issue: https://bugs.openjdk.java.net/browse/JDK-8031482
>>>   Webrev: http://cr.openjdk.java.net/~gadams/8031482
>>>
>>> testing in progress ...
>>
>>
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: RFR: JDK-8031482: Some jcmd commands generate output with \n as a line separator instead of \r\n on Windows

David Holmes
In reply to this post by Gary Adams-3
Hi Gary,

On 12/01/2018 2:28 AM, Gary Adams wrote:
> Here's a simple fix to the split pattern when output lines are using
> mixed line separators in the same outputstream . e.g. split("\r\n|\n")

This is rather crude. I'd prefer to see reuse of existing library
classes that already handle all the supported versions of newlines.
BufferedReader does that.

private List<String> asLines(String buffer) {
     return new BufferedReader(new
StringReader(buffer)).lines().collect(Collectors.toList());
   }

Going forward we could stream-ify outputAnalyzer further. :)

Cheers,
David
-----

import java.util.stream.Collectors;
import java.util.List;
import java.io.BufferedReader;
import java.io.StringReader;

public class Lines {
   public static void main(String[] args) {
     List<String> l = asLines("Line1\nLine2\r\nLine3\rLine4");
     for (String s : l) {
       System.out.println(s);
     }
   }
   static private List<String> asLines(String buffer) {
     return new BufferedReader(new
StringReader(buffer)).lines().collect(Collectors.toList());
   }
}


>
>    Issue: https://bugs.openjdk.java.net/browse/JDK-8031482
>    Webrev: http://cr.openjdk.java.net/~gadams/JDK-8031482
>
> testing in progress ...
Reply | Threaded
Open this post in threaded view
|

Re: RFR: JDK-8031482: Some jcmd commands generate output with \n as a line separator instead of \r\n on Windows

Gary Adams-3
In reply to this post by Gary Adams-3
Webrev updated with buffered reader lines() suggested by David.

   http://cr.openjdk.java.net/~gadams/8031482/webrev.01/

On 1/11/18 11:28 AM, Gary Adams wrote:
> Here's a simple fix to the split pattern when output lines are using
> mixed line
> separators in the same outputstream . e.g. split("\r\n|\n")
>
>   Issue: https://bugs.openjdk.java.net/browse/JDK-8031482
>   Webrev: http://cr.openjdk.java.net/~gadams/JDK-8031482
>
> testing in progress ...


Reply | Threaded
Open this post in threaded view
|

Re: RFR: JDK-8031482: Some jcmd commands generate output with \n as a line separator instead of \r\n on Windows

David Holmes
Looks good - thanks. I'll sponsor for you.

David

On 13/01/2018 11:05 PM, [hidden email] wrote:

> Webrev updated with buffered reader lines() suggested by David.
>
>    http://cr.openjdk.java.net/~gadams/8031482/webrev.01/
>
> On 1/11/18 11:28 AM, Gary Adams wrote:
>> Here's a simple fix to the split pattern when output lines are using
>> mixed line
>> separators in the same outputstream . e.g. split("\r\n|\n")
>>
>>   Issue: https://bugs.openjdk.java.net/browse/JDK-8031482
>>   Webrev: http://cr.openjdk.java.net/~gadams/JDK-8031482
>>
>> testing in progress ...
>
>
Reply | Threaded
Open this post in threaded view
|

Re: RFR: JDK-8031482: Some jcmd commands generate output with \n as a line separator instead of \r\n on Windows

David Holmes
Opps sorry one more thing:

     /**
      * Get the contents of the output buffer (stdout and stderr) as
list of strings.
      * Output will be split by system property 'line.separator'.

the doc comment needs to be updated e.g:

* Output will be split at new-lines as recognized by
java.io.BufferedReader.readLine()

Thanks,
David

On 14/01/2018 8:47 AM, David Holmes wrote:

> Looks good - thanks. I'll sponsor for you.
>
> David
>
> On 13/01/2018 11:05 PM, [hidden email] wrote:
>> Webrev updated with buffered reader lines() suggested by David.
>>
>>    http://cr.openjdk.java.net/~gadams/8031482/webrev.01/
>>
>> On 1/11/18 11:28 AM, Gary Adams wrote:
>>> Here's a simple fix to the split pattern when output lines are using
>>> mixed line
>>> separators in the same outputstream . e.g. split("\r\n|\n")
>>>
>>>   Issue: https://bugs.openjdk.java.net/browse/JDK-8031482
>>>   Webrev: http://cr.openjdk.java.net/~gadams/JDK-8031482
>>>
>>> testing in progress ...
>>
>>