Skip to content

Commit

Permalink
8260: Warnings and errors logged during XML processing
Browse files Browse the repository at this point in the history
Reviewed-by: hirt
  • Loading branch information
Virag Purnam committed Oct 14, 2024
1 parent eead093 commit cf85dbc
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public void deserialize(String xmlSource) throws IOException, SAXException {
factory.setExpandEntityReferences(false);
factory.setValidating(true);
builder = factory.newDocumentBuilder();
builder.setErrorHandler(null);
} catch (ParserConfigurationException e) {
// This should not happen anyway
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ public static Document createNewDocument(String rootElementName) throws IOExcept
InputSource xml = new InputSource(
new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?><" + rootElementName + "/>")); //$NON-NLS-1$ //$NON-NLS-2$
DocumentBuilderFactory dbf = createDocumentBuildFactoryInstance();

doc = dbf.newDocumentBuilder().parse(xml);
DocumentBuilder documentBuilder = dbf.newDocumentBuilder();
documentBuilder.setErrorHandler(null);
doc = documentBuilder.parse(xml);
} catch (IOException e) {
// just rethrow
throw e;
Expand Down Expand Up @@ -380,6 +381,7 @@ private static DocumentBuilder getDocumentBuilder() {
try {
DocumentBuilderFactory factory = createDocumentBuildFactoryInstance();
docBuilder = factory.newDocumentBuilder();
docBuilder.setErrorHandler(null);
} catch (ParserConfigurationException e) {
// This shouldn't happen since all configuration is done within XmlToolkit
LOGGER.log(Level.WARNING, "Parser configuration error", e); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public static XMLModel create(InputSource input, IXMLValidator validator) throws
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
XMLModelBuilder dataHandler = new XMLModelBuilder(dummyRoot);
xr.setErrorHandler(null);
xr.setContentHandler(dataHandler);
xr.parse(input);
List<XMLTagInstance> instances = dummyRoot.getTagsInstances();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ private static ReportCollection parseRulesReportXml(String directory, String fil
docFactory.setFeature(XML_PARSER_DISALLOW_DOCTYPE_ATTRIBUTE, true);
docFactory.setValidating(true);
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
docBuilder.setErrorHandler(null);
Document baselineDoc = docBuilder.parse(file);
collection = ReportCollection.fromXml(baselineDoc, reportName);
} catch (ParserConfigurationException | SAXException | IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.ErrorHandler;

public class ListVersions {
private static final String XML_PARSER_DISALLOW_DOCTYPE_ATTRIBUTE = "http://apache.org/xml/features/disallow-doctype-decl"; //$NON-NLS-1$
Expand Down Expand Up @@ -100,6 +101,7 @@ public static Map<String, String> getNewVersions(String eclipseVersion) {
dbFactory.setFeature(XML_PARSER_DISALLOW_DOCTYPE_ATTRIBUTE, true);
dbFactory.setValidating(true);
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
dBuilder.setErrorHandler(null);
Document compositeDoc = dBuilder.parse(compositeZipStream);

NodeList childrenList = compositeDoc.getElementsByTagName("child");
Expand Down

0 comments on commit cf85dbc

Please sign in to comment.