JDK-8276207 : Properties.loadFromXML/storeToXML works incorrectly for supplementary characters
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-10-31
  • Updated: 2021-11-06
  • Resolved: 2021-11-06
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.
JDK 18
18 masterFixed
Related Reports
Relates :  
Relates :  
Description
Properties.loadFromXML/storeToXML works incorrectly for supplementary characters after JDK-8042889 was integrated in JDK 9.

Execute the below program to store Properties with supplementary characters :

------------------------------------------------------------------------------------------------------------------------
import java.util.Properties;

public class PropertiesStoreSupplementaryCharacters {

	public static void main(String[] args) throws Exception {
		Properties properties = new Properties();

		properties.put("Emoticons", "\uD83D\uDE03");
		properties.put("Musical Symbols", "\uD834\uDD1E");
		properties.put("CJK Unified Ideographs Extension B", "\uD840\uDC0B");

		properties.storeToXML(System.out, null);
	}

}
------------------------------------------------------------------------------------------------------------------------


Output on JDK 8 is :
------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="Emoticons">&#128515;</entry>
<entry key="Musical Symbols">&#119070;</entry>
<entry key="CJK Unified Ideographs Extension B">&#131083;</entry>
</properties>
------------------------------------------------------------------------------------------------------------------------


Output on JDK 17 is :
------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="Emoticons">&#xd83d;&#xde03;</entry>
<entry key="Musical Symbols">&#xd834;&#xdd1e;</entry>
<entry key="CJK Unified Ideographs Extension B">&#xd840;&#xdc0b;</entry>
</properties>
------------------------------------------------------------------------------------------------------------------------

The numeric character references in JDK 17 is incorrect.


Execute the below program to load Properties with supplementary characters :

------------------------------------------------------------------------------------------------------------------------
import java.io.ByteArrayInputStream;
import java.util.Properties;

public class PropertiesLoadSupplementaryCharacters {

	public static void main(String[] args) throws Exception {
		Properties expected = new Properties();
		expected.put("\uD834\uDD1E", "\uD834\uDD1E");

		String s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            	"<!DOCTYPE properties SYSTEM \"http://java.sun.com/dtd/properties.dtd\">" +
                "<properties>" +
                "<entry key=\"&#119070;\">&#x1d11e;</entry>" +
                "</properties>";

		ByteArrayInputStream in = new ByteArrayInputStream(s.getBytes("UTF-8"));
		Properties props = new Properties();
		props.loadFromXML(in);

		if (props.equals(expected)) {
			System.out.println("Loaded and Expected properties are same");
		} else {
			System.out.println("Loaded and Expected properties are diferent");
			System.out.println("loaded: " + props + ", expected: " + expected);
		}
	}

}
------------------------------------------------------------------------------------------------------------------------

On JDK 8 it properly parses the character references. Loaded and Expected properties are same.

On JDK 17 it fails to parse the character references and throws InvalidPropertiesFormatException with below stack trace:
------------------------------------------------------------------------------------------------------------------------
Exception in thread "main" java.util.InvalidPropertiesFormatException: jdk.internal.org.xml.sax.SAXParseException; 
	at java.base/jdk.internal.util.xml.PropertiesDefaultHandler.load(PropertiesDefaultHandler.java:85)
	at java.base/java.util.Properties.loadFromXML(Properties.java:960)
	at com.openjdk.PropertiesLoadSupplementaryCharacters.main(PropertiesLoadSupplementaryCharacters.java:20)
Caused by: jdk.internal.org.xml.sax.SAXParseException; 
	at java.base/jdk.internal.util.xml.impl.ParserSAX.panic(ParserSAX.java:652)
	at java.base/jdk.internal.util.xml.impl.Parser.ent(Parser.java:1997)
	at java.base/jdk.internal.util.xml.impl.Parser.bqstr(Parser.java:2594)
	at java.base/jdk.internal.util.xml.impl.Parser.attr(Parser.java:1378)
	at java.base/jdk.internal.util.xml.impl.Parser.step(Parser.java:407)
	at java.base/jdk.internal.util.xml.impl.ParserSAX.parse(ParserSAX.java:477)
	at java.base/jdk.internal.util.xml.impl.ParserSAX.parse(ParserSAX.java:411)
	at java.base/jdk.internal.util.xml.impl.ParserSAX.parse(ParserSAX.java:374)
	at java.base/jdk.internal.util.xml.impl.SAXParserImpl.parse(SAXParserImpl.java:97)
	at java.base/jdk.internal.util.xml.PropertiesDefaultHandler.load(PropertiesDefaultHandler.java:83)
	... 2 more
------------------------------------------------------------------------------------------------------------------------
Comments
Changeset: c7095b20 Author: Anirvan Sarkar <asarkar@openjdk.org> Committer: Joe Wang <joehw@openjdk.org> Date: 2021-11-06 00:41:44 +0000 URL: https://git.openjdk.java.net/jdk/commit/c7095b20d956e154d9863a7928d26285f1a0a0ac
06-11-2021

Hi Alan, yes, will do. Thanks.
01-11-2021

[~joehw] Do you mind commenting on this issue?
31-10-2021