src/share/classes/sun/util/xml/PlatformXmlPropertiesProvider.java

Print this page

        

@@ -25,10 +25,11 @@
 
 package sun.util.xml;
 
 import java.io.*;
 import java.util.*;
+import java.nio.charset.*;
 import org.xml.sax.*;
 import org.w3c.dom.*;
 import javax.xml.parsers.*;
 import javax.xml.transform.*;
 import javax.xml.transform.dom.*;

@@ -125,10 +126,17 @@
     @Override
     public void store(Properties props, OutputStream os, String comment,
                       String encoding)
         throws IOException
     {
+        // fast-fail for unsupported charsets as UnsupportedEncodingException may
+        // not be thrown later (see JDK-8000621)
+        try {
+            Charset.forName(encoding);
+        } catch (IllegalCharsetNameException | UnsupportedCharsetException x) {
+            throw new UnsupportedEncodingException(encoding);
+        }
         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
         DocumentBuilder db = null;
         try {
             db = dbf.newDocumentBuilder();
         } catch (ParserConfigurationException pce) {