-
Bug
-
Resolution: Unresolved
-
P3
-
None
-
6u14
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Internal reading (XMLEntityScanner) of the second 8kb Block (ScannedEntity.DEFAULT_BUFFER_SIZE) of the DTD delivers some invalid data (or skip some attributes) if you set another Charset in InputStreamReader than the encoding of the DTD.
This does not occur in Java5 or below!
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create an XML refering an DTD (which is bigger than 8kb and using encoding "UTF-8").
Put XML/DTD in a JAR-Library, let it load from following code.
ACTUAL -
java -jar Java6XMLProblemProof.jar
### INFO: Start parsing ...
### INFO: complete DTD-Path: ./disp-masks.dtd
### INFO: DTD loading from Classpath ...
Found [0] <jar:file:/C:/Dokumente%20und%20Einstellungen/mikr/Eigene%20Dateien/NetBeansProjects/Java6XMLProblemProof/dist/Java
6XMLProblemProof.jar!/disp-masks.dtd>
Result of resolveEntity(): <org.xml.sax.InputSource@1ac3c08>
[Fatal Error] disp-masks.dtd:138:4: The attribute type is required in the declaration of attribute "D" for element "TableInpu
t".
org.xml.sax.SAXParseException: The attribute type is required in the declaration of attribute "D" for element "TableInput".
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at ProblemProof.main(ProblemProof.java:49)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
[Fatal Error] disp-masks.dtd:138:4: The attribute type is required in the declaration of attribute "D" for element "TableInput".
org.xml.sax.SAXParseException: The attribute type is required in the declaration of attribute "D" for element "TableInput".
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at ProblemProof.main(ProblemProof.java:49)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
---------- ProblemProof.java --------
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import org.xml.sax.InputSource;
public class ProblemProof
{
protected final static String xmlEncoding = "ISO-8859-15";
protected static Charset xmlEncodingCharset = null;
static
{
xmlEncodingCharset = Charset.forName( xmlEncoding );
}
public static void main( String[] args )
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try
{
// Using factory get an instance of document builder
DocumentBuilder db = dbf.newDocumentBuilder();
// Create Classloader for using XML-File from JAR-Library
ClassLoader cl = ProblemProof.class.getClassLoader();
InputStream is = cl.getResourceAsStream( "Templates.xml" );
//InputStream is = cl.getResourceAsStream( "xml/sample.xml" );
db.setEntityResolver( new JarLoadingEntityResolver() );
// parse using builder to get DOM representation of the XML file
// NOTE: Somwhere in Parsing the DTD of Sample-Xml occures an error
InputStreamReader inReader = new InputStreamReader( is,
xmlEncodingCharset );
System.out.println( "### INFO: Start parsing ..." );
Document dom = db.parse( new InputSource( inReader ) );//is );
System.out.println( "### INFO: Parsing successful!" );
}
catch( ParserConfigurationException pce )
{
pce.printStackTrace();
}
catch( SAXException se )
{
se.printStackTrace();
}
catch( IOException ioe )
{
ioe.printStackTrace();
}
catch( Throwable th )
{
th.printStackTrace();
}
}
}
---------- JarLoadingEntityResolver.java --------
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import java.io.*;
import java.net.URLDecoder;
import java.util.Enumeration;
public class JarLoadingEntityResolver
implements EntityResolver
{
public InputSource resolveEntity( String publicId, String systemId )
throws SAXException, IOException
{
InputSource result = null;
String strDTDPathJar = null;
String strDTDPathFile = null;
try
{
try
{
systemId = systemId.replace( '\\', '/' );
systemId = URLDecoder.decode( systemId, "UTF-8" );
String strbPathDTD = /*"xml/" +*/ systemId.substring( systemId.lastIndexOf( "/" ) + 1 );
strDTDPathFile = systemId;
if(strDTDPathFile.startsWith( "file:" ) )
{
strDTDPathFile = strDTDPathFile.substring( "file:".length() );
}
System.out.println( "### INFO: complete DTD-Path: "
+ strDTDPathFile);
System.out.println(
"### INFO: DTD loading from Classpath ..." );
strDTDPathJar = strbPathDTD.toString();
if( strDTDPathJar != null )
{
if( strDTDPathJar.startsWith( "file:" ) )
{
strDTDPathJar =
strDTDPathJar.substring( "file:".length() );
}
if( strDTDPathJar.startsWith( "./" ) )
{
strDTDPathJar = strDTDPathJar.substring( 2 );
}
ClassLoader cl = getClass().getClassLoader();
Enumeration foundList = cl.getResources( strDTDPathJar );
for( int i = 0; foundList.hasMoreElements(); i++ )
{
System.out.println( "Found [" +i +"] <"
+ foundList.nextElement() +">" );
}
java.io.InputStream inputStream =
cl.getResourceAsStream( strDTDPathJar );
if( inputStream != null )
{
result = new InputSource( inputStream );
result.setSystemId( systemId );
result.setPublicId( publicId );
result.setEncoding( ProblemProof.xmlEncoding );
}
else
{
System.out.println(
"### ERROR: DTD Path could not be opened <"
+ strDTDPathJar +">" );
}
}
else
{
System.out.println( "### ERROR: DTD Path is [NULL]" );
}
}
catch( FileNotFoundException fnfe )
{
System.out.println( "DTD File could not be opened!");
fnfe.printStackTrace();
}
}
catch( Exception ex )
{
System.out.println( "Exception! Try to load DTD from Classpath ..." );
ex.printStackTrace();
File entityFile = new File( systemId );
String strShortName = entityFile.getName();
java.io.InputStream dtdFileStream =
ClassLoader.getSystemResourceAsStream( strShortName );
result = new InputSource(new InputStreamReader(dtdFileStream));
}
if(result != null)
{
System.out.println( "Result of resolveEntity(): <" + result + ">" );
}
else
{
System.out.println( "Result of resolveEntity is NULL!!");
}
return result;
}
}
-------- Loading DTD File of the XML ------
....
spaceTop CDATA #IMPLIED
spanX CDATA #IMPLIED
----- position 8192 -----
spanY CDATA #IMPLIED
visible (y | n) #IMPLIED
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Don't set a different Encoding for the used InputStreamReader!
Release Regression From : 5.0
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.
Release Regression From : 5.0
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Internal reading (XMLEntityScanner) of the second 8kb Block (ScannedEntity.DEFAULT_BUFFER_SIZE) of the DTD delivers some invalid data (or skip some attributes) if you set another Charset in InputStreamReader than the encoding of the DTD.
This does not occur in Java5 or below!
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create an XML refering an DTD (which is bigger than 8kb and using encoding "UTF-8").
Put XML/DTD in a JAR-Library, let it load from following code.
ACTUAL -
java -jar Java6XMLProblemProof.jar
### INFO: Start parsing ...
### INFO: complete DTD-Path: ./disp-masks.dtd
### INFO: DTD loading from Classpath ...
Found [0] <jar:file:/C:/Dokumente%20und%20Einstellungen/mikr/Eigene%20Dateien/NetBeansProjects/Java6XMLProblemProof/dist/Java
6XMLProblemProof.jar!/disp-masks.dtd>
Result of resolveEntity(): <org.xml.sax.InputSource@1ac3c08>
[Fatal Error] disp-masks.dtd:138:4: The attribute type is required in the declaration of attribute "D" for element "TableInpu
t".
org.xml.sax.SAXParseException: The attribute type is required in the declaration of attribute "D" for element "TableInput".
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at ProblemProof.main(ProblemProof.java:49)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
[Fatal Error] disp-masks.dtd:138:4: The attribute type is required in the declaration of attribute "D" for element "TableInput".
org.xml.sax.SAXParseException: The attribute type is required in the declaration of attribute "D" for element "TableInput".
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at ProblemProof.main(ProblemProof.java:49)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
---------- ProblemProof.java --------
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import org.xml.sax.InputSource;
public class ProblemProof
{
protected final static String xmlEncoding = "ISO-8859-15";
protected static Charset xmlEncodingCharset = null;
static
{
xmlEncodingCharset = Charset.forName( xmlEncoding );
}
public static void main( String[] args )
{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try
{
// Using factory get an instance of document builder
DocumentBuilder db = dbf.newDocumentBuilder();
// Create Classloader for using XML-File from JAR-Library
ClassLoader cl = ProblemProof.class.getClassLoader();
InputStream is = cl.getResourceAsStream( "Templates.xml" );
//InputStream is = cl.getResourceAsStream( "xml/sample.xml" );
db.setEntityResolver( new JarLoadingEntityResolver() );
// parse using builder to get DOM representation of the XML file
// NOTE: Somwhere in Parsing the DTD of Sample-Xml occures an error
InputStreamReader inReader = new InputStreamReader( is,
xmlEncodingCharset );
System.out.println( "### INFO: Start parsing ..." );
Document dom = db.parse( new InputSource( inReader ) );//is );
System.out.println( "### INFO: Parsing successful!" );
}
catch( ParserConfigurationException pce )
{
pce.printStackTrace();
}
catch( SAXException se )
{
se.printStackTrace();
}
catch( IOException ioe )
{
ioe.printStackTrace();
}
catch( Throwable th )
{
th.printStackTrace();
}
}
}
---------- JarLoadingEntityResolver.java --------
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import java.io.*;
import java.net.URLDecoder;
import java.util.Enumeration;
public class JarLoadingEntityResolver
implements EntityResolver
{
public InputSource resolveEntity( String publicId, String systemId )
throws SAXException, IOException
{
InputSource result = null;
String strDTDPathJar = null;
String strDTDPathFile = null;
try
{
try
{
systemId = systemId.replace( '\\', '/' );
systemId = URLDecoder.decode( systemId, "UTF-8" );
String strbPathDTD = /*"xml/" +*/ systemId.substring( systemId.lastIndexOf( "/" ) + 1 );
strDTDPathFile = systemId;
if(strDTDPathFile.startsWith( "file:" ) )
{
strDTDPathFile = strDTDPathFile.substring( "file:".length() );
}
System.out.println( "### INFO: complete DTD-Path: "
+ strDTDPathFile);
System.out.println(
"### INFO: DTD loading from Classpath ..." );
strDTDPathJar = strbPathDTD.toString();
if( strDTDPathJar != null )
{
if( strDTDPathJar.startsWith( "file:" ) )
{
strDTDPathJar =
strDTDPathJar.substring( "file:".length() );
}
if( strDTDPathJar.startsWith( "./" ) )
{
strDTDPathJar = strDTDPathJar.substring( 2 );
}
ClassLoader cl = getClass().getClassLoader();
Enumeration foundList = cl.getResources( strDTDPathJar );
for( int i = 0; foundList.hasMoreElements(); i++ )
{
System.out.println( "Found [" +i +"] <"
+ foundList.nextElement() +">" );
}
java.io.InputStream inputStream =
cl.getResourceAsStream( strDTDPathJar );
if( inputStream != null )
{
result = new InputSource( inputStream );
result.setSystemId( systemId );
result.setPublicId( publicId );
result.setEncoding( ProblemProof.xmlEncoding );
}
else
{
System.out.println(
"### ERROR: DTD Path could not be opened <"
+ strDTDPathJar +">" );
}
}
else
{
System.out.println( "### ERROR: DTD Path is [NULL]" );
}
}
catch( FileNotFoundException fnfe )
{
System.out.println( "DTD File could not be opened!");
fnfe.printStackTrace();
}
}
catch( Exception ex )
{
System.out.println( "Exception! Try to load DTD from Classpath ..." );
ex.printStackTrace();
File entityFile = new File( systemId );
String strShortName = entityFile.getName();
java.io.InputStream dtdFileStream =
ClassLoader.getSystemResourceAsStream( strShortName );
result = new InputSource(new InputStreamReader(dtdFileStream));
}
if(result != null)
{
System.out.println( "Result of resolveEntity(): <" + result + ">" );
}
else
{
System.out.println( "Result of resolveEntity is NULL!!");
}
return result;
}
}
-------- Loading DTD File of the XML ------
....
spaceTop CDATA #IMPLIED
spanX CDATA #IMPLIED
----- position 8192 -----
spanY CDATA #IMPLIED
visible (y | n) #IMPLIED
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Don't set a different Encoding for the used InputStreamReader!
Release Regression From : 5.0
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.
Release Regression From : 5.0
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.