Source:
<code>private SaxEventToXmlElementConverter startConstructingElement( String uri, String localName, Attributes atts) throws XMLStreamException { Multimap<String, String> addedNamespaces = ArrayListMultimap.create(); if (scopeOfNamespacesAdded.peek() != null) { addedNamespaces.putAll(scopeOfNamespacesAdded.peek()); } scopeOfNamespacesAdded.push(addedNamespaces); Map<String, String> scopedNamespaces = new HashMap<>(); Iterator<NamespaceMapping> iter = namespaceStack.descendingIterator(); while (iter.hasNext()) { NamespaceMapping tmpPair = iter.next(); scopedNamespaces.put(tmpPair.getUri(), tmpPair.getPrefix()); } out.writeStartElement(scopedNamespaces.get(uri), localName, uri); if (!checkNamespaceAdded(uri, scopedNamespaces)) { out.writeNamespace(scopedNamespaces.get(uri), uri); addedNamespaces.put(uri, scopedNamespaces.get(uri)); } for (int i = 0; i < atts.getLength(); i++) { if (atts.getURI(i).isEmpty()) { out.writeAttribute(atts.getLocalName(i), atts.getValue(i)); } else { String attUri = atts.getURI(i); if (!checkNamespaceAdded(attUri, scopedNamespaces)) { out.writeNamespace(scopedNamespaces.get(attUri), attUri); addedNamespaces.put(attUri, scopedNamespaces.get(attUri)); } try { out.writeAttribute( scopedNamespaces.get(attUri), attUri, atts.getLocalName(i), atts.getValue(i)); } catch (XMLStreamException e) { Optional<String> altNs = namespaceStack .stream() .filter(p -> attUri.equals(p.getUri()) && !(p.getPrefix().isEmpty())) .map(NamespaceMapping::getPrefix) <START> .findFirst(); <END> if (altNs.isPresent()) { out.writeNamespace(altNs.get(), attUri); addedNamespaces.put(attUri, altNs.get()); out.writeAttribute(altNs.get(), attUri, atts.getLocalName(i), atts.getValue(i)); } } } } return this; }</code><technical_language>Add '.orElse(null)' avoid calling isPresent get it. again, simply add .ifPresent(altNs -> { code })</technical_language>

Target:
private SaxEventToXmlElementConverter startConstructingElement( String uri, String localName, Attributes atts) throws XMLStreamException { Multimap<String, String> addedNamespaces = ArrayListMultimap.create(); if (scopeOfNamespacesAdded.peek() != null) { addedNamespaces.putAll(scopeOfNamespacesAdded.peek()); } scopeOfNamespacesAdded.push(addedNamespaces); Map<String, String> scopedNamespaces = new HashMap<>(); Iterator<NamespaceMapping> iter = namespaceStack.descendingIterator(); while (iter.hasNext()) { NamespaceMapping tmpPair = iter.next(); scopedNamespaces.put(tmpPair.getUri(), tmpPair.getPrefix()); } out.writeStartElement(scopedNamespaces.get(uri), localName, uri); if (!checkNamespaceAdded(uri, scopedNamespaces)) { out.writeNamespace(scopedNamespaces.get(uri), uri); addedNamespaces.put(uri, scopedNamespaces.get(uri)); } for (int i = 0; i < atts.getLength(); i++) { if (atts.getURI(i).isEmpty()) { out.writeAttribute(atts.getLocalName(i), atts.getValue(i)); } else { String attUri = atts.getURI(i); if (!checkNamespaceAdded(attUri, scopedNamespaces)) { out.writeNamespace(scopedNamespaces.get(attUri), attUri); addedNamespaces.put(attUri, scopedNamespaces.get(attUri)); } try { out.writeAttribute( scopedNamespaces.get(attUri), attUri, atts.getLocalName(i), atts.getValue(i)); } catch (XMLStreamException e) { handleNamespaceDupes(atts, addedNamespaces, i, attUri); } } } return this; }