Skip to content

AbstractXmlStreamReader getAttributeValue(String, String) does not handle null namespaceURI properly [SPR-7474] #12132

@spring-projects-issues

Description

@spring-projects-issues

Eduard Papa opened SPR-7474 and commented

According to the javadoc for XMLStreamReader, when a null namespaceURI is passed to getAttributeValue(String, String), the method should return the attribute value without matching the namespace URI.

Javadoc:
http://download-llnw.oracle.com/javase/6/docs/api/javax/xml/stream/XMLStreamReader.html#getAttributeValue%28java.lang.String,%20java.lang.String%29

AbstractXmlStreamReader is not handling that condition correctly and tries to match the attribute's namespace with null:

if (name.getNamespaceURI().equals(namespaceURI) && name.getLocalPart().equals(localName)) {
   return getAttributeValue( i ) ;
}
return null;

This results in getAttributeValue returning null whenever the namespaceURI parameter is null.

The fix would be to change the code above as follows:

if (*(namespaceURI == null || name.getNamespaceURI().equals(namespaceURI))* && name.getLocalPart().equals(localName)) {
   return getAttributeValue( i ) ;
}
return null;

Please note that this problem exists in two classes:
org.springframework.util.xml.AbstractXmlStreamReader in Spring-Core 3.0.3
org.springframework.xml.stream.AbstractXmlStreamReader in Spring-Xml 1.5.9


Affects: 3.0.3

Attachments:

Referenced from: commits 061b2c9

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions