<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'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't using the BasicParserPool errorHandler </div><div>LoggingErrorHandler so parsing doesn'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 = "<xtest xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\" "</div><div><span class="" style="white-space:pre">                                </span>+ "xmlns:XMLSchema-instance=\"<a href="http://www.w3.org/2001/XMLSchema-instance\">http://www.w3.org/2001/XMLSchema-instance\</a>">"</div><div><span class="" style="white-space:pre">                                </span>+ "</xtest>";<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("Won't get here:" +
                                        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("Expected:"+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("Shouldn't get here:" +
                                        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>