JDK-6256805 : LTP: XMLEncoder emits invalid XML
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2005-04-18
  • Updated: 2011-03-14
  • Resolved: 2006-03-30
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 6
6 b78Fixed
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
True for Windows and Linux (all versions)

A DESCRIPTION OF THE PROBLEM :
XMLEncoder will produce invalid XML under a range of circumstances.  Valid characters in XML (from http://www.w3.org/TR/REC-xml/) are:

"Character Range
[2]   	Char	   ::=   	#x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]	/* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */
"

No character that is outside this range may be put in an XML file.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Any function that returns a string where ANY of the characters are not permitted by the XML specification, or any method that returns a char where the char is not in the permitted range.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Strings should be  encoded (Base64) before saving them to the file.  Characters could be saved as ints or encoded strings.
ACTUAL -
Invalid characters are encoded directly into the file.

REPRODUCIBILITY :
This bug can be reproduced always.
###@###.### 2005-04-18 19:36:08 GMT

Comments
EVALUATION I introduced attribute code for element <char>. The code contains hexadecimal value if it starts with '#'. Otherwise it contains decimal value.
21-11-2005

EVALUATION If the characters are not legal in XML (control chars #0-8, for example), they will have to be replaced with something that is legal. It is often suggested that you convert such characters to processing instructions like <?char 7?> or elements like <char num="7"/>. I think that processing instructions are preferable than elements because they are never used in ObjectHandler. Base64 encoding is not good solution because we can't recognize encoded and/or decoded strings. And we have to encode all strings and characters in XML document even if it is not necessary.
19-10-2005

EVALUATION We should conform to recomendation ###@###.### 2005-06-06 15:52:12 GMT
06-06-2005