Skip to content

Commit

Permalink
More lgtm.com warnings fixes: got 12, this should remove 5 of them.
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 21, 2021
1 parent 61ab7e9 commit e313616
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 55 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/ctc/wstx/dtd/DTDAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,10 @@ protected String validateDefaultNames(InputProblemReporter rep, boolean normaliz
+"'; empty String is not a valid name value");
}

return normalize ? sb.toString() : defValue;
return (sb != null) ? sb.toString() : defValue;
}


protected String validateDefaultNmToken(InputProblemReporter rep, boolean normalize)
throws XMLStreamException
{
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/ctc/wstx/dtd/DTDNmTokensAttr.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ public String validate(DTDValidatorBase v, char[] cbuf, int start, int end, bool
//trimmed = true;
}

/* Ok, now, need to check we only have valid chars, and maybe
* also coalesce multiple spaces, if any.
*/
// Ok, now, need to check we only have valid chars, and maybe
// also coalesce multiple spaces, if any.
StringBuilder sb = null;

while (start <= end) {
Expand Down Expand Up @@ -131,7 +130,7 @@ public String validate(DTDValidatorBase v, char[] cbuf, int start, int end, bool
* avoid using StringBuilder... but let's only do it if it turns
* out dealing with NMTOKENS normalization shows up on profiling...
*/
return sb.toString();
return (sb == null) ? null : sb.toString();
}

/**
Expand Down Expand Up @@ -201,7 +200,7 @@ public void validateDefault(InputProblemReporter rep, boolean normalize)
return;
}

if (normalize) {
if (sb != null) {
mDefValue.setValue(sb.toString());
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/ctc/wstx/sr/BasicStreamReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2448,9 +2448,11 @@ protected final void parseQuoted(String name, char quoteChar, TextBuffer tbuf)
break;
}
if (c < CHAR_SPACE || c == '<') {
throwUnexpectedChar(c, SUFFIX_IN_XML_DECL);
} else if (c == CHAR_NULL) {
throwNullChar();
if (c == CHAR_NULL) {
throwNullChar();
} else {
throwUnexpectedChar(c, SUFFIX_IN_XML_DECL);
}
}
if (outPtr >= outBuf.length) {
outBuf = tbuf.finishCurrentSegment();
Expand Down Expand Up @@ -5274,8 +5276,6 @@ private int readAndWriteText(Writer w)
} else {
; // !!! TBI: how to check past boundary?
}
} else if (c == CHAR_NULL) {
throwNullChar();
}
}
} // while (true)
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/ctc/wstx/sr/StreamScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -1738,8 +1738,9 @@ private EntityDecl expandUnresolvedEntity(String id)
newInput = DefaultInputResolver.resolveEntityUsing
(oldInput, id, null, null, resolver, mConfig, xmlVersion);
if (mCfgTreatCharRefsAsEntities) {
return new IntEntity(WstxInputLocation.getEmptyLocation(), newInput.getEntityId(),
newInput.getSource(), new char[]{}, WstxInputLocation.getEmptyLocation());
return new IntEntity(WstxInputLocation.getEmptyLocation(),
newInput.getEntityId(), newInput.getSource(), // lgtm [java/dereferenced-value-may-be-null]
new char[]{}, WstxInputLocation.getEmptyLocation());
}
} catch (IOException ioe) {
throw constructFromIOE(ioe);
Expand Down
40 changes: 0 additions & 40 deletions src/main/java/com/ctc/wstx/util/TextBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -822,46 +822,6 @@ public boolean isAllWhitespace()
return true;
}

/**
* Method that can be used to check if the contents of the buffer end
* in specified String.
*
* @return True if the textual content buffer contains ends with the
* specified String; false otherwise
*/
public boolean endsWith(String str)
{
// Let's just play this safe; should seldom if ever happen...
// and because of that, can be sub-optimal, performancewise, to
// alternatives.
if (mInputStart >= 0) {
unshare(16);
}

int segIndex = (mSegments == null) ? 0 : mSegments.size();
int inIndex = str.length() - 1;
char[] buf = mCurrentSegment;
int bufIndex = mCurrentSize-1;

while (inIndex >= 0) {
if (str.charAt(inIndex) != buf[bufIndex]) {
return false;
}
if (--inIndex == 0) {
break;
}
if (--bufIndex < 0) {
if (--segIndex < 0) { // no more data?
return false;
}
buf = mSegments.get(segIndex);
bufIndex = buf.length-1;
}
}

return true;
}

/**
* Note: it is assumed that this method is not used often enough to
* be a bottleneck, or for long segments. Based on this, it is optimized
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/wstxtest/util/TestTextBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public void testBasic()

assertEquals(INPUT, tb.toString());
assertEquals(INPUT, tb.contentsAsString());
assertFalse(tb.endsWith("shor"));
assertTrue(tb.endsWith("so as not to be too short"));
assertFalse(tb.isAllWhitespace());

assertTrue(tb.equalsString(INPUT));
Expand Down

0 comments on commit e313616

Please sign in to comment.