JDK-8000621 : serializer.setEncoding emits warning message for unrecognized encoding, falls back to UTF-8
  • Type: Bug
  • Component: xml
  • Sub-Component: jaxp
  • Affected Version: 6,7,8
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • Submitted: 2012-10-09
  • Updated: 2019-08-01
  • Resolved: 2019-08-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Relates :  
Relates :  
Relates :  
Description
Consider the following test case:

import java.util.*;
import java.io.*;

public class Test {
    public static void main(String[] args) throws Exception {
	Properties props = System.getProperties();

	try (OutputStream out = new FileOutputStream("props.xml")) {
	    props.storeToXML(out, "comment", "Vinnie");
	}
    }
}

When run it prints the following to the console:

Warning:  The encoding 'Vinnie' is not supported by the Java runtime.
Warning: encoding "Vinnie" not supported, using UTF-8

It's very impolite for the JDK to print messages to the console, this should be an exception instead.


Comments
I'm closing this issue as it's no longer an issue in java.util.Properties after the change to the underlying parser. For the issue in JAXP, I've created a CSR (JDK-8228973) to fix the specification and then the impl.
01-08-2019

It's true this is still an issue in JAXP. New test case: StreamSource source = new StreamSource(new StringReader("<foo><bar></bar></foo>")); StreamResult result = new StreamResult(new StringWriter()); Transformer tform = TransformerFactory.newInstance().newTransformer(); tform.setOutputProperty(OutputKeys.ENCODING, "dummy"); tform.transform(source, result); It looks like there's also an issue in that the ErrorListener was not called.
27-07-2019

Tested against JDK 8, 9 and 13. Same result (UnsupportedEncodingException) as Brian indicated previously, although the stacktrace has changed. JDK 13 now does an earlier check: Exception in thread "main" java.io.UnsupportedEncodingException: Vinnie at java.base/java.util.Properties.storeToXML(Properties.java:1044) at JDK8000621Test.main(JDK8000621Test.java:9) The result is as specified: UnsupportedEncodingException - if the encoding is not supported by the implementation.
26-07-2019

I've changed the fixVersion to tbd_minor as this issue is not new and is not critical to be done in 8.
21-09-2013

Thanks, Alan. I downgraded it to P4.
21-09-2013

Properties has been updated (see http://ccc.us.oracle.com/8000685) so it may be necessary to write a test case that uses JAXP directly. Note that this is not critical for JDK 8 as the issue has always existed. It's also okay to make this a P4.
21-09-2013

Using the current jdk8/tl repository this does not manifest as warnings any more but rather as an exception: Exception in thread "main" java.io.UnsupportedEncodingException: Vinnie at sun.util.xml.PlatformXmlPropertiesProvider.store(PlatformXmlPropertiesProvider.java:136) at java.util.Properties$XmlSupport.save(Properties.java:1213) at java.util.Properties.storeToXML(Properties.java:958) at Test.main(Test.java:11) This was tested on Mac OS 10.7.5.
20-09-2013

What the issue revealed is a lack of value check on the setOutputProperty and setOutputProperties methods in javax.xml.transform.Transformer. It would require specification change.
04-12-2012