From 5b619ab138d1878b67f5876aec0cf2a34a23f642 Mon Sep 17 00:00:00 2001 From: sideshowbarker Date: Tue, 20 Feb 2024 09:44:41 +0900 Subject: [PATCH] Prevent NPE in HtmlAttributes.getIndex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apparently it’s possible for a “mode” value to be such that AttributeName.getQName(mode) returns null. So this change adds a null check to catch that. Otherwise, without this change, some documents cause that code to throw a NullPointerException. --- src/nu/validator/htmlparser/impl/HtmlAttributes.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nu/validator/htmlparser/impl/HtmlAttributes.java b/src/nu/validator/htmlparser/impl/HtmlAttributes.java index 7f747c3a..e21bde26 100644 --- a/src/nu/validator/htmlparser/impl/HtmlAttributes.java +++ b/src/nu/validator/htmlparser/impl/HtmlAttributes.java @@ -184,7 +184,8 @@ public AttributeName getAttributeNameNoBoundsCheck(int index) { public int getIndex(String qName) { for (int i = 0; i < length; i++) { - if (names[i].getQName(mode).equals(qName)) { + if (names[i].getQName(mode) != null && + names[i].getQName(mode).equals(qName)) { return i; } }