-
assigned issue to
Chase Tingley
The following test code will fail:
StringBuilder sb = new StringBuilder();
sb.append(enc.encode(']', EncoderContext.TEXT));
sb.append(enc.encode(']', EncoderContext.TEXT));
sb.append(enc.encode('>', EncoderContext.TEXT));
assertEquals("]]>", sb.toString());
The XMLEncoder will write out ]]> instead. This is invalid XML (that char sequence is only allowed when terminating a CDATA section. It's also inconsistent behavior within the encoder itself, because this passes:
assertEquals("]]>", enc.encode("]]>", EncoderContext.TEXT));
The XMLEncoder probably needs to track state across calls to encode(char), so it can provide consistent and correct behavior. ie, in all cases calling encode(String) should be equivalent to calling encode(char) on each char of the String in succession.