Skip to content

Commit b1aa398

Browse files
committed
fix some pmd warnings
1 parent e91515c commit b1aa398

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

src/main/java/org/htmlunit/html/BaseFrameElement.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -387,26 +387,32 @@ public final void setSrcAttribute(final String attribute) {
387387
* {@inheritDoc}
388388
*/
389389
@Override
390-
protected void setAttributeNS(final String namespaceURI, final String qualifiedName, String attributeValue,
390+
protected void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue,
391391
final boolean notifyAttributeChangeListeners, final boolean notifyMutationObserver) {
392392
final String qualifiedNameLC = org.htmlunit.util.StringUtils.toRootLowerCase(qualifiedName);
393+
393394
if (null != attributeValue && SRC_ATTRIBUTE.equals(qualifiedNameLC)) {
394-
attributeValue = attributeValue.trim();
395-
}
395+
final String attributeValueTrimmed = attributeValue.trim();
396396

397-
super.setAttributeNS(namespaceURI, qualifiedNameLC, attributeValue, notifyAttributeChangeListeners,
398-
notifyMutationObserver);
397+
super.setAttributeNS(namespaceURI, qualifiedNameLC, attributeValueTrimmed, notifyAttributeChangeListeners,
398+
notifyMutationObserver);
399399

400-
// do not use equals() here
401-
// see HTMLIFrameElement2Test.documentCreateElement_onLoad_srcAboutBlank()
402-
if (SRC_ATTRIBUTE.equals(qualifiedNameLC) && UrlUtils.ABOUT_BLANK != attributeValue) {
403-
if (isAttachedToPage()) {
404-
loadSrc();
405-
}
406-
else {
407-
loadSrcWhenAddedToPage_ = true;
400+
// do not use equals() here
401+
// see HTMLIFrameElement2Test.documentCreateElement_onLoad_srcAboutBlank()
402+
if (UrlUtils.ABOUT_BLANK != attributeValueTrimmed) {
403+
if (isAttachedToPage()) {
404+
loadSrc();
405+
}
406+
else {
407+
loadSrcWhenAddedToPage_ = true;
408+
}
408409
}
410+
411+
return;
409412
}
413+
414+
super.setAttributeNS(namespaceURI, qualifiedNameLC, attributeValue, notifyAttributeChangeListeners,
415+
notifyMutationObserver);
410416
}
411417

412418
/**

src/main/java/org/htmlunit/html/DomNode.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,13 @@ public DomNode getFirstChild() {
335335
* @param node the node to check
336336
* @return {@code true} if this node is an ancestor of the specified node
337337
*/
338-
public boolean isAncestorOf(DomNode node) {
339-
while (node != null) {
340-
if (node == this) {
338+
public boolean isAncestorOf(final DomNode node) {
339+
DomNode parent = node;
340+
while (parent != null) {
341+
if (parent == this) {
341342
return true;
342343
}
343-
node = node.getParentNode();
344+
parent = parent.getParentNode();
344345
}
345346
return false;
346347
}

src/main/java/org/htmlunit/util/StringUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,21 +241,21 @@ public static boolean containsIgnoreCase(final String s, final String expected)
241241
* @param replaceChars a set of characters to replace, may be null.
242242
* @return modified String, or the input string if no replace was done.
243243
*/
244-
public static String replaceChars(final String str, final String searchChars, String replaceChars) {
244+
@SuppressWarnings("null")
245+
public static String replaceChars(final String str, final String searchChars, final String replaceChars) {
245246
if (isEmptyOrNull(str) || isEmptyOrNull(searchChars)) {
246247
return str;
247248
}
248249

249-
replaceChars = replaceChars == null ? "" : replaceChars;
250-
final int replaceCharsLength = replaceChars.length();
250+
final int replaceCharsLength = replaceChars == null ? 0 : replaceChars.length();
251251
final int strLength = str.length();
252252

253253
StringBuilder buf = null;
254254
int i = 0;
255255
for ( ; i < strLength; i++) {
256256
final char ch = str.charAt(i);
257257
final int index = searchChars.indexOf(ch);
258-
if (index >= 0) {
258+
if (index != -1) {
259259
buf = new StringBuilder(strLength);
260260
buf.append(str, 0, i);
261261
if (index < replaceCharsLength) {
@@ -273,7 +273,7 @@ public static String replaceChars(final String str, final String searchChars, St
273273
for ( ; i < strLength; i++) {
274274
final char ch = str.charAt(i);
275275
final int index = searchChars.indexOf(ch);
276-
if (index >= 0) {
276+
if (index != -1) {
277277
if (index < replaceCharsLength) {
278278
buf.append(replaceChars.charAt(index));
279279
}

0 commit comments

Comments
 (0)