Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 518909

Summary: Regression: IOConsoleOutputStream.setEncoding(String) cannot handle null argument anymore
Product: [Eclipse Project] Platform Reporter: Andreas Loth <andy_2639>
Component: DebugAssignee: Andreas Loth <andy_2639>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: sarika.sinha
Version: 4.7   
Target Milestone: 4.7 M1   
Hardware: All   
OS: All   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=507664
Whiteboard:
Attachments:
Description Flags
Test case for setting null encoding
none
Fix for setting null encoding none

Description Andreas Loth CLA 2017-06-28 15:53:57 EDT
This regression was introduced with https://bugs.eclipse.org/bugs/show_bug.cgi?id=507664 .

Code of IOConsoleOutputStream.setEncoding(String) in 4.6:

	public void setEncoding(String encoding) {
		fEncoding = encoding;
		fNeedsEncoding = (fEncoding!=null) && (!fEncoding.equals(fDefaultEncoding));
...

Code in 4.7:

	public void setEncoding(String encoding) {
		Charset charset = Charset.forName(encoding);


In 4.6, encoding = null is handled explicitly and results in using the default encoding.
In 4.7, encoding = null leads to an exception thrown by Charset.forName(string).

A fix for 4.7 could be

	public void setEncoding(String encoding) {
		Charset charset;
		if (encoding == null) {
			charset = Charset.forName(WorkbenchEncoding.getWorkbenchDefaultEncoding());
		} else {
			charset = Charset.forName(encoding);
		}
...

I can provide a patch including testcase. However, this will take a while because I have limited Internet access (and time) in the next 2 weeks.
Comment 1 Sarika Sinha CLA 2017-07-04 00:10:55 EDT
Thanks Andreas!!
Comment 2 Andreas Loth CLA 2017-07-08 09:23:55 EDT
Created attachment 269292 [details]
Test case for setting null encoding
Comment 3 Andreas Loth CLA 2017-07-08 09:32:28 EDT
Created attachment 269293 [details]
Fix for setting null encoding