Skip to content

Commit

Permalink
Fix #121 (last 5 lgtm.com's warnings should now be gone)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 24, 2021
1 parent 76bc355 commit b83d48f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 47 deletions.
4 changes: 4 additions & 0 deletions release-notes/VERSION
Expand Up @@ -4,6 +4,10 @@ Project: woodstox
=== Releases ===
------------------------------------------------------------------------

Not yet released:

#121: Fix issues outlined by "lgtm.com"'s static analysis

6.2.7 (20-Nov-2021)

#132: `copyEventFromReader()` Processing Instruction event bug
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/ctc/wstx/dtd/DTDIdAttr.java
Expand Up @@ -18,9 +18,9 @@ public final class DTDIdAttr
extends DTDAttribute
{
/*
///////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// Life-cycle
///////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
*/

/**
Expand All @@ -44,9 +44,9 @@ public DTDAttribute cloneWith(int specIndex) {
}

/*
///////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// Public API
///////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
*/

@Override
Expand All @@ -60,9 +60,9 @@ public boolean typeIsId() {
}

/*
///////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// Public API, validation
///////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
*/

/**
Expand Down
40 changes: 21 additions & 19 deletions src/main/java/com/ctc/wstx/dtd/DTDTypingNonValidator.java
Expand Up @@ -37,10 +37,10 @@
public class DTDTypingNonValidator
extends DTDValidatorBase
{
/*
///////////////////////////////////////////
/*
///////////////////////////////////////////////////////////////////////
// Element def/spec/validator stack, state
///////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
*/

/**
Expand All @@ -63,21 +63,21 @@ public class DTDTypingNonValidator
protected boolean mHasNormalizableAttrs = false;

/*
///////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// Temporary helper objects
///////////////////////////////////////
///////////////////////////////////////////////////////////////////////
*/

/**
* Reusable lazily instantiated BitSet; needed to keep track of
* 'missing' attributes with default values (normal default, #FIXED).
*/
BitSet mTmpDefaultAttrs;
protected BitSet mTmpDefaultAttrs;

/*
///////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// Life-cycle
///////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
*/

public DTDTypingNonValidator(DTDSubset schema, ValidationContext ctxt, boolean hasNsDefaults,
Expand All @@ -93,9 +93,9 @@ public DTDTypingNonValidator(DTDSubset schema, ValidationContext ctxt, boolean h
public final boolean reallyValidating() { return false; }

/*
///////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// Configuration
///////////////////////////////////////
///////////////////////////////////////////////////////////////////////
*/

/**
Expand All @@ -108,9 +108,9 @@ public void setAttrValueNormalization(boolean state) {
}

/*
///////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// XMLValidator implementation
///////////////////////////////////////
///////////////////////////////////////////////////////////////////////
*/

//public XMLValidationSchema getSchema()
Expand Down Expand Up @@ -253,7 +253,11 @@ public int validateElementAndAttributes()
* attribute default values, and return "anything goes"
* as the allowable content:
*/
DTDElement elem = mCurrElem;
final DTDElement elem = mCurrElem;
if (elem == null) { // can this ever occur really?
return XMLValidator.CONTENT_ALLOW_ANY_TEXT;
}

if (mHasAttrDefaults) {
BitSet specBits = mCurrDefaultAttrs;
int specCount = elem.getSpecialCount();
Expand All @@ -271,11 +275,9 @@ public int validateElementAndAttributes()
* to occur -- although it won't be considered an error, when not
* validating, info is needed to determine type of SPACE instead
* of CHARACTERS. Other validation types are not to be returned,
* however, since caller doesn't know how to deal with such
* cases.
* however, since caller doesn't know how to deal with such cases.
*/
return (elem == null) ? XMLValidator.CONTENT_ALLOW_ANY_TEXT :
elem.getAllowedContentIfSpace();
return elem.getAllowedContentIfSpace();
}

@Override
Expand Down Expand Up @@ -307,9 +309,9 @@ public void validationCompleted(boolean eod)
}

/*
///////////////////////////////////////
///////////////////////////////////////////////////////////////////////
// Package methods, accessors
///////////////////////////////////////
///////////////////////////////////////////////////////////////////////
*/

@Override
Expand Down
39 changes: 17 additions & 22 deletions src/main/java/com/ctc/wstx/sr/AttributeCollector.java
Expand Up @@ -46,7 +46,7 @@
*/
public final class AttributeCollector
{
final static int INT_SPACE = 0x0020;
protected final static int INT_SPACE = 0x0020;

/**
* Threshold value that indicates minimum length for lists instances
Expand Down Expand Up @@ -798,7 +798,7 @@ public final TextBuilder getAttrBuilder(String attrPrefix, String attrLocalName)
mAttributes[0] = new Attribute(attrPrefix, attrLocalName, 0);
} else {
int valueStart = mValueBuilder.getCharSize();
if (mAttrCount >= mAttributes.length) {
if (mAttrCount >= mAttributes.length) { // lgtm [java/dereferenced-value-may-be-null]
if ((mAttrCount + mNsCount) >= mMaxAttributesPerElement) {
throw new XMLStreamException("Attribute limit ("+mMaxAttributesPerElement+") exceeded");
}
Expand Down Expand Up @@ -920,18 +920,17 @@ public TextBuilder getNsBuilder(String prefix) throws XMLStreamException
mNamespaces[0] = new Attribute(null, prefix, 0);
} else {
int len = mNsCount;
/* Ok: must ensure that there are no duplicate namespace
* declarations (ie. decls with same prefix being bound)
*/
// Ok: must ensure that there are no duplicate namespace
// declarations (ie. decls with same prefix being bound)
if (prefix != null) { // null == default ns
for (int i = 0; i < len; ++i) {
// note: for ns decls, bound prefix is in 'local name'
if (prefix == mNamespaces[i].mLocalName) {
if (prefix == mNamespaces[i].mLocalName) { // lgtm [java/dereferenced-value-may-be-null]
return null;
}
}
}
if (len >= mNamespaces.length) {
if (len >= mNamespaces.length) { // lgtm [java/dereferenced-value-may-be-null]
if ((mAttrCount + mNsCount) >= mMaxAttributesPerElement) {
throw new XMLStreamException("Attribute limit ("+mMaxAttributesPerElement+") exceeded");
}
Expand Down Expand Up @@ -1000,15 +999,13 @@ public int resolveNamespaces(InputProblemReporter rep, StringVector ns)
*/
int[] map = mAttrMap;

/* What's minimum size to contain at most 80% full hash area,
* plus 1/8 spill area (12.5% spilled entries, two ints each)?
*/
// What's minimum size to contain at most 80% full hash area,
// plus 1/8 spill area (12.5% spilled entries, two ints each)?
int hashCount = 4;
{
int min = attrCount + (attrCount >> 2); // == 80% fill rate
/* Need to get 2^N size that can contain all elements, with
* 80% fill rate
*/
// Need to get 2^N size that can contain all elements, with
// 80% fill rate
while (hashCount < min) {
hashCount += hashCount; // 2x
}
Expand All @@ -1018,10 +1015,9 @@ public int resolveNamespaces(InputProblemReporter rep, StringVector ns)
if (map == null || map.length < min) {
map = new int[min];
} else {
/* Need to clear old hash entries (if any). But note that
* spilled entries we can leave alone -- they are just ints,
* and get overwritten if and as needed
*/
// Need to clear old hash entries (if any). But note that
// spilled entries we can leave alone -- they are just ints,
// and get overwritten if and as needed
Arrays.fill(map, 0, hashCount, 0);
}
}
Expand All @@ -1041,14 +1037,13 @@ public int resolveNamespaces(InputProblemReporter rep, StringVector ns)
}
int index = hash & mask;
// Hash slot available?
if (map[index] == 0) {
if (map[index] == 0) { // lgtm [java/dereferenced-value-may-be-null]
map[index] = i+1; // since 0 is marker
} else {
int currIndex = map[index]-1;
/* nope, need to spill; let's extract most of that code to
* a separate method for clarity (and maybe it'll be
* easier to inline by JVM too)
*/
// nope, need to spill; let's extract most of that code to
// a separate method for clarity (and maybe it'll be
// easier to inline by JVM too)
map = spillAttr(uri, name, map, currIndex, spillIndex,
hash, hashCount);
if (map == null) {
Expand Down

0 comments on commit b83d48f

Please sign in to comment.