{"record":{"id":"13f64a8dc7ec6ea5","repo":"stanfordnlp/CoreNLP","slug":"error-configuring-xml-parser-e","errorCode":null,"errorMessage":"Error configuring XML parser: ${e}","messagePattern":"Error configuring XML parser: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/process/TransformXML.java","lineNumber":203,"sourceCode":"    @Override\n    public void processText(String text) {\n      if (text.length() > 0) {\n        text = function.apply(text).toString();\n        outWriter.print(text);\n        outWriter.print('\\n');\n      }\n    }    \n  }\n\n\n  public TransformXML() {\n    try {\n      SAXParserFactory spf = SAXParserFactory.newInstance();\n      spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);\n      saxParser = spf.newSAXParser();\n    } catch (Exception e) {\n      log.info(\"Error configuring XML parser: \" + e);\n      throw new RuntimeException(e);\n    }\n  }\n\n\n  /**\n   * Read XML from the specified file and write XML to stdout,\n   * while transforming text appearing inside the specified XML\n   * tags by applying the specified {@link Function\n   * <code>Function</code>}.  Note that the <code>Function</code>\n   * you supply must be prepared to accept <code>String</code>s as\n   * input; if your <code>Function</code> doesn't handle\n   * <code>String</code>s, you need to write a wrapper for it that\n   * does.\n   *\n   * @param tags an array of <code>String</code>s, each an XML tag\n   *             within which the transformation should be applied\n   * @param fn   the {@link Function <code>Function</code>} to apply\n   * @param in   the <code>File</code> to read from","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/process/TransformXML.java#L185-L221","documentation":"TransformXML's constructor configures a secure SAXParserFactory. If the JAXP factory cannot be created or the secure-processing feature cannot be set, the exception is logged and rethrown as RuntimeException. This usually indicates a broken or unusual JAXP/SAX environment.","triggerScenarios":"Constructing TransformXML when SAXParserFactory.newInstance() returns a misconfigured factory, or spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true) throws ParserConfigurationException/SAXNotRecognizedException — e.g. a non-standard JAXP implementation on the classpath.","commonSituations":"Conflicting XML parser jars (xercesImpl, old sax jars) shadowing the JDK's; running on restricted runtimes where FEATURE_SECURE_PROCESSING is unsupported; broken META-INF/services javax.xml.parsers.SAXParserFactory entry.","solutions":["Remove conflicting XML parser jars (xerces, old SAX implementations) from the classpath so the JDK default parser is used","If using a custom parser, upgrade it to one supporting FEATURE_SECURE_PROCESSING","Set the system property javax.xml.parsers.SAXParserFactory explicitly to a working implementation","Unwrap the cause (the RuntimeException's cause) to identify which setup step failed"],"exampleFix":"// before (classpath has stale xercesImpl-2.0.jar)\njava -cp lib/*:app.jar Main\n// after\nrm lib/xercesImpl-2.0.jar\njava -cp lib/*:app.jar Main","handlingStrategy":"try-catch","validationCode":"try {\n  SAXParserFactory.newInstance().newSAXParser();\n} catch (Exception e) {\n  throw new IllegalStateException(\"No working JAXP SAX parser on classpath\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n  new TransformXML<String>();\n} catch (RuntimeException e) {\n  e.getCause().printStackTrace(); // parser config failure\n}","preventionTips":["Keep only one XML parser implementation on the classpath","Test JAXP parser availability at app startup","Avoid embedding stale xerces/sax jars in fat JARs"],"tags":["java","xml","sax","configuration"],"backgroundTag":"module-init-failed","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}