[java-support] 01/02: JSPT-113 - Implement conventional contract for AttributeSupport.hasAttribute
Ian Young
ian at iay.org.uk
Tue Mar 1 17:06:21 UTC 2022
This is an automated email from the git hooks/post-receive script.
iay pushed a commit to branch main
in repository java-support.
View the commit online:
http://git.shibboleth.net/view/?p=java-support.git;a=commit;h=78010de686d4d49ae14c61c1faa53885be49357a
commit 78010de686d4d49ae14c61c1faa53885be49357a
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Tue Mar 1 17:05:47 2022 +0000
JSPT-113 - Implement conventional contract for AttributeSupport.hasAttribute
https://shibboleth.atlassian.net/browse/JSPT-113
---
.../net/shibboleth/utilities/java/support/xml/AttributeSupport.java | 2 +-
.../shibboleth/utilities/java/support/xml/AttributeSupportTest.java | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/main/java/net/shibboleth/utilities/java/support/xml/AttributeSupport.java b/src/main/java/net/shibboleth/utilities/java/support/xml/AttributeSupport.java
index 5a6f599..20d2578 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/xml/AttributeSupport.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/xml/AttributeSupport.java
@@ -469,7 +469,7 @@ public final class AttributeSupport {
* @return true if the element has an attribute with the given name, false otherwise
*/
public static boolean hasAttribute(@Nullable final Element element, @Nullable final QName name) {
- if (element == name || name == null) {
+ if (element == null || name == null) {
return false;
}
diff --git a/src/test/java/net/shibboleth/utilities/java/support/xml/AttributeSupportTest.java b/src/test/java/net/shibboleth/utilities/java/support/xml/AttributeSupportTest.java
index ac128ba..d72d0f3 100644
--- a/src/test/java/net/shibboleth/utilities/java/support/xml/AttributeSupportTest.java
+++ b/src/test/java/net/shibboleth/utilities/java/support/xml/AttributeSupportTest.java
@@ -297,6 +297,10 @@ public class AttributeSupportTest {
}
@Test public void testHasAttribute() {
+ // either parameter null means a false result, not an NPE
+ Assert.assertFalse(AttributeSupport.hasAttribute(null, idAttrQName));
+ Assert.assertFalse(AttributeSupport.hasAttribute(createdElement, null));
+
Assert.assertFalse(AttributeSupport.hasAttribute(createdElement, idAttrQName), "Attribute lookup by QName");
Assert.assertTrue(AttributeSupport.hasAttribute(goodBaseIdSpaceLang, XMLConstants.XML_BASE_ATTRIB_NAME),
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list