<div dir="ltr">We ran into an issue that the first call to BasicParserPool.parse fails but the second call with the same xml doesn&#39;t fail.<div><br></div><div>I looked through the code and method on BasicParserPool: <span class="" style="white-space:pre">        </span>public void returnBuilder(DocumentBuilder builder)</div><div>calls </div><div><div><span class="" style="white-space:pre">                        </span>unwrappedBuilder.reset();</div></div><div><br></div><div>which resets the entityResolver and errorHandler back to the default constructor versions.</div><div>So next time when using a parser from the pool it isn&#39;t using the BasicParserPool errorHandler </div><div>LoggingErrorHandler so parsing doesn&#39;t fail.</div><div><br></div><div>Example code set xml to an invalid xml string like missing a namespace.</div><div><br></div><div><span style="white-space:pre">                // smallest xml to force error.</span><br></div><div><div><span class="" style="white-space:pre">                </span>String xmlString = &quot;&lt;xtest xmlns:saml=\&quot;urn:oasis:names:tc:SAML:2.0:assertion\&quot; &quot;</div><div><span class="" style="white-space:pre">                                </span>+ &quot;xmlns:XMLSchema-instance=\&quot;<a href="http://www.w3.org/2001/XMLSchema-instance\">http://www.w3.org/2001/XMLSchema-instance\</a>&quot;&gt;&quot;</div><div><span class="" style="white-space:pre">                                </span>+ &quot;&lt;/xtest&gt;&quot;;<br></div></div><div><br></div><div><div><span class="" style="white-space:pre">                </span>Configuration.getBuilderFactory();</div><div><span class="" style="white-space:pre">                </span>BasicParserPool parser = new BasicParserPool();</div><div><span class="" style="white-space:pre">                </span>parser.setNamespaceAware(true);</div><div><span class="" style="white-space:pre">                </span>parser.setIgnoreElementContentWhitespace(true);</div><div><span class="" style="white-space:pre">                </span>parser.setSchema(SAMLSchemaBuilder.getSAML11Schema());</div><div><br></div><div><span class="" style="white-space:pre">                </span>try</div><div><span class="" style="white-space:pre">                </span>{</div><div><span class="" style="white-space:pre">                        </span>Document doc = parser.parse(new StringReader(xmlString));</div><div><br></div><span style="white-space:pre">                        System.out.println(&quot;Won&#39;t get here:&quot; +
                                        doc);
</span><div><span class="" style="white-space:pre">                </span>}<br></div><div><span class="" style="white-space:pre">                </span>catch (Exception ex)</div><div><span class="" style="white-space:pre">                </span>{</div><div><span class="" style="white-space:pre">                        </span>System.out.println(&quot;Expected:&quot;+ex.getMessage());</div><div><span style="white-space:pre">                        </span>// ex.printStackTrace();</div><div><span class="" style="white-space:pre">                </span>}</div><div><br></div><div><span style="white-space:pre">                </span><span style="white-space:pre">try
                {
                        Document doc = parser.parse(new StringReader(xmlString));

                        System.out.println(&quot;Shouldn&#39;t get here:&quot; +
                                        doc);
                }
                catch (Exception ex)
                {
                        ex.printStackTrace();
                }
<br></span></div></div><div><span style="white-space:pre">If I added setting entityResolver/errorHandler after result it tosses an exception on second call:</span></div><div><span style="white-space:pre">                        unwrappedBuilder.reset();</span></div><div><span style="white-space:pre">                        // add these 2 lines to get error on second call.</span><span style="white-space:pre">
                        unwrappedBuilder.setEntityResolver(entityResolver);
                        unwrappedBuilder.setErrorHandler(errorHandler);
</span></div><div><span style="white-space:pre"><br></span></div><div><br></div></div>