Source:
<code>public CertificationResultRules() { Document dom; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(false); dbf.setCoalescing(true); dbf.setExpandEntityReferences(true); dbf.setIgnoringComments(true); dbf.setIgnoringElementContentWhitespace(true); ClassPathResource cpr = new ClassPathResource("certificationResultRules.xml"); try { <START> try (InputStream xmlInput = cpr.getInputStream()) { <END> DocumentBuilder db = dbf.newDocumentBuilder(); dom = db.parse(xmlInput); Element doc = dom.getDocumentElement(); NodeList certNodes = doc.getElementsByTagName("certificationResult"); for (int i = 0; i < certNodes.getLength(); i++) { Element certNode = (Element) certNodes.item(i); String certNumber = getTextValue(certNode, "number"); NodeList propertiesNodes = certNode.getElementsByTagName("properties"); if (propertiesNodes.getLength() == 1) { Element certProperties = (Element) propertiesNodes.item(0); NodeList certPropertiesNodes = certProperties.getChildNodes(); for (int j = 0; j < certPropertiesNodes.getLength(); j++) { Node propertyNode = certPropertiesNodes.item(j); if (propertyNode instanceof Element) { Element propertyElement = (Element) propertyNode; String propName = propertyElement.getNodeName(); String propValue = propertyElement.getTextContent(); boolean canHaveProperty = new Boolean(propValue).booleanValue(); CertificationResultOption option = new CertificationResultOption(); option.setOptionName(propName); if(propName.equals("gap")){ option.setCanHaveOption(true); }else{ option.setCanHaveOption(canHaveProperty); } if (rules.get(certNumber) == null) { List<CertificationResultOption> options = new ArrayList<CertificationResultOption>(); options.add(option); rules.put(certNumber, options); } else { rules.get(certNumber).add(option); } } } } } } } catch (final ParserConfigurationException pce) { LOGGER.error(pce.getMessage(), pce); } catch (final SAXException se) { LOGGER.error(se.getMessage(), se); } catch (final IOException ioe) { LOGGER.error(ioe.getMessage(), ioe); } }</code><technical_language>A double try again</technical_language>

Target:
public CertificationResultRules() { Document dom; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(false); dbf.setCoalescing(true); dbf.setExpandEntityReferences(true); dbf.setIgnoringComments(true); dbf.setIgnoringElementContentWhitespace(true); ClassPathResource cpr = new ClassPathResource("certificationResultRules.xml"); try (InputStream xmlInput = cpr.getInputStream()) { DocumentBuilder db = dbf.newDocumentBuilder(); dom = db.parse(xmlInput); Element doc = dom.getDocumentElement(); NodeList certNodes = doc.getElementsByTagName("certificationResult"); for (int i = 0; i < certNodes.getLength(); i++) { Element certNode = (Element) certNodes.item(i); String certNumber = getTextValue(certNode, "number"); NodeList propertiesNodes = certNode.getElementsByTagName("properties"); if (propertiesNodes.getLength() == 1) { Element certProperties = (Element) propertiesNodes.item(0); NodeList certPropertiesNodes = certProperties.getChildNodes(); for (int j = 0; j < certPropertiesNodes.getLength(); j++) { Node propertyNode = certPropertiesNodes.item(j); if (propertyNode instanceof Element) { Element propertyElement = (Element) propertyNode; String propName = propertyElement.getNodeName(); String propValue = propertyElement.getTextContent(); boolean canHaveProperty = new Boolean(propValue).booleanValue(); CertificationResultOption option = new CertificationResultOption(); option.setOptionName(propName); if(propName.equals("gap")){ option.setCanHaveOption(true); }else{ option.setCanHaveOption(canHaveProperty); } if (rules.get(certNumber) == null) { List<CertificationResultOption> options = new ArrayList<CertificationResultOption>(); options.add(option); rules.put(certNumber, options); } else { rules.get(certNumber).add(option); } } } } } } catch (final ParserConfigurationException pce) { LOGGER.error(pce.getMessage(), pce); } catch (final SAXException se) { LOGGER.error(se.getMessage(), se); } catch (final IOException ioe) { LOGGER.error(ioe.getMessage(), ioe); } }