JDK-6333923 : Using javax.xml.transform causes an annoying warning message to be written to System.err
  • Type: Bug
  • Component: xml
  • Sub-Component: javax.xml.transform
  • Affected Version: 6
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2005-10-07
  • Updated: 2012-04-25
  • Resolved: 2005-12-14
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 b61Fixed
Related Reports
Duplicate :  
Duplicate :  
Description
The most trivial use of the javax.xml.transform API in Mustang causes the
message "Warning: Could not get charToByteConverterClass!" to be written to
System.err.  This is extremely annoying.  It's also a compatibility issue since
most existing applications probably aren't expecting random libraries to write
unsolicited messages to System.err.

Code to reproduce the problem:

----
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;

public class Bug {

    public static void main(String[] args) throws Exception {
	TransformerFactory tff = TransformerFactory.newInstance();
	Transformer tf = tff.newTransformer();
	byte[] in = new byte[] { (byte)'<', (byte)'x', (byte)'/', (byte)'>' };
	tf.transform(new StreamSource(new ByteArrayInputStream(in)),
		     new StreamResult(new FileOutputStream("/dev/null")));
    }

}
----

Comments
EVALUATION There's some unfortunate code in org.apache.xml.internal.serializer.Encodings which assumes the existence of the sun.io package, and in particular of a class named CharToByteConverter within that package. These are internal APIs that should never be used by code outside of the core of Sun's Java SE implementations. We've been warning developers about this for nearly ten years (http://java.sun.com/products/jdk/faq/faq-sun-packages.html). In any case that the CharToByteConverter class, and indeed the entire sun.io package, were removed early in Mustang (6237353). The Xalan code that depends upon them should be removed, or at the very least silenced.
07-10-2005

SUGGESTED FIX This is just a short-term fix. The proper fix is to remove all of the logic in org.apache.xml.internal.serializer.Encodings and related classes that assumes the existence of the sun.io package. *** /tmp/geta17805 Thu Oct 6 21:23:42 2005 --- src/share/classes/com/sun/org/apache/xml/internal/serializer/Encodings.java Thu Oct 6 21:23:42 2005 *************** *** 66,92 **** SUN_CHAR2BYTE_CONVERTER_METHOD = findCharToByteConverterMethod(); private static Method findCharToByteConverterMethod() { - try - { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - try { - Class charToByteConverterClass = (Class) - Class.forName("sun.io.CharToByteConverter"); - Class argTypes[] = {String.class}; - return charToByteConverterClass.getMethod("getConverter", argTypes); - } - catch (Exception e) { - throw new RuntimeException(e.toString()); - } - }}); - } - catch (Exception e) - { - System.err.println( - "Warning: Could not get charToByteConverterClass!"); - } - return null; }
07-10-2005