JDK-8317425 : PrintStream does not allow the line separator to be overridden
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 19
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2023-10-02
  • Updated: 2023-10-09
  • Resolved: 2023-10-03
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE PROBLEM :
Duplicate of https://bugs.java.com/bugdatabase/view_bug?bug_id=8294410
with source code to reproduce.


---------- BEGIN SOURCE ----------
public class Main {
	
    public static void main(String[] args) throws java.io.IOException {    	
    	System.out.println("First separator's length = " + System.getProperty("line.separator").length() + ".");
    	System.out.print("First multiline string will be small. It's length = ");
    	System.out.println(getString().length() + ".");
    	System.out.println();
    	
    	System.setProperty("line.separator", "e".repeat(100));
    	System.out.println("Second separator's length = " + System.getProperty("line.separator").length() + ".");
    	System.out.print("Second multiline string should be huge. It's length = ");
    	System.out.println(getString().length() + ".");   
    }
    
    public static String getString() throws java.io.IOException {
    	try (java.io.PipedOutputStream pipeOut = new java.io.PipedOutputStream();
    			java.io.PipedInputStream pipeIn = new java.io.PipedInputStream();
    			java.io.PrintStream outputStream = new java.io.PrintStream(pipeOut);
    			) {
    		pipeOut.connect(pipeIn);
    		outputStream.println("q");
    		outputStream.println("w");
    		outputStream.close();

    		return new String(pipeIn.readAllBytes());
    	}   
    }
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Moved the information to JDK-8294410. Close this report as duplicate.
03-10-2023