Skip to content

Commit

Permalink
fix spotbugs static analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Oct 15, 2023
1 parent 8f161f3 commit 0749c37
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 33 deletions.
14 changes: 7 additions & 7 deletions gradle/config/pmd/rulesSets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
<rule ref="category/java/bestpractices.xml/LooseCoupling">
<properties>
<property name="allowedTypes" value="
java.util.Properties
,java.util.concurrent.ConcurrentHashMap
,com.google.common.collect.ImmutableMap
,com.google.common.collect.ImmutableSet
,com.google.common.collect.ImmutableList
,com.github.benmanes.caffeine.cache.BoundedLocalCache
,com.github.benmanes.caffeine.cache.UnboundedLocalCache
java.util.Properties,
java.util.concurrent.ConcurrentHashMap,
com.google.common.collect.ImmutableMap,
com.google.common.collect.ImmutableSet,
com.google.common.collect.ImmutableList,
com.github.benmanes.caffeine.cache.BoundedLocalCache,
com.github.benmanes.caffeine.cache.UnboundedLocalCache
"/>
</properties>
</rule>
Expand Down
37 changes: 37 additions & 0 deletions gradle/config/spotbugs/exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
CFS_CONFUSING_FUNCTION_SEMANTICS,
CLI_CONSTANT_LIST_INDEX,
CNC_COLLECTION_NAMING_CONFUSION,
CT_CONSTRUCTOR_THROW,
DMI_RANDOM_USED_ONLY_ONCE,
EI_EXPOSE_REP, EI_EXPOSE_REP2,
ENMI_EQUALS_ON_ENUM,
Expand All @@ -39,6 +40,8 @@
OI_OPTIONAL_ISSUES_CHECKING_REFERENCE,
OPM_OVERLY_PERMISSIVE_METHOD,
PCOA_PARTIALLY_CONSTRUCTED_OBJECT_ACCESS,
PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES,
PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_FIELD_NAMES,
PIS_POSSIBLE_INCOMPLETE_SERIALIZATION,
PL_PARALLEL_LISTS,
PMB_INSTANCE_BASED_THREAD_LOCAL,
Expand All @@ -54,6 +57,8 @@
THROWS_METHOD_THROWS_RUNTIMEEXCEPTION,
THROWS_METHOD_THROWS_CLAUSE_BASIC_EXCEPTION,
URV_UNRELATED_RETURN_VALUES,
UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD,
UWF_UNWRITTEN_FIELD,
USBR_UNNECESSARY_STORE_BEFORE_RETURN,
UTWR_USE_TRY_WITH_RESOURCES,
UVA_USE_VAR_ARGS,
Expand Down Expand Up @@ -214,10 +219,27 @@
<Class name="com.github.benmanes.caffeine.cache.WriteThroughEntry"/>
<Bug pattern="EQ_DOESNT_OVERRIDE_EQUALS"/>
</Match>
<Match>
<Or>
<Class name="~.*FD.*"/>
<Class name="~.*FS.*"/>
<Class name="~.*FW.*"/>
<Class name="~.*PD.*"/>
<Class name="~.*PS.*"/>
<Class name="~.*PW.*"/>
</Or>
<Bug pattern="NP_UNWRITTEN_FIELD"/>
</Match>
<Match>
<Or>
<Class name="~.*Mpsc.*"/>
<Class name="~.*Header.*"/>
<Class name="~.*FD.*"/>
<Class name="~.*FS.*"/>
<Class name="~.*FW.*"/>
<Class name="~.*PD.*"/>
<Class name="~.*PS.*"/>
<Class name="~.*PW.*"/>
</Or>
<Bug pattern="UUF_UNUSED_FIELD"/>
</Match>
Expand All @@ -226,6 +248,11 @@
<Method name="main"/>
<Bug pattern="PATH_TRAVERSAL_IN"/>
</Match>
<Match>
<Class name="com.github.benmanes.caffeine.cache.LocalCacheFactoryGenerator"/>
<Method name="reformat"/>
<Bug pattern="DM_DEFAULT_ENCODING"/>
</Match>
<Match>
<Class name="com.github.benmanes.caffeine.cache.LocalCacheFactoryGenerator"/>
<Method name="reformat"/>
Expand All @@ -236,11 +263,21 @@
<Method name="main"/>
<Bug pattern="PATH_TRAVERSAL_IN"/>
</Match>
<Match>
<Class name="com.github.benmanes.caffeine.cache.NodeFactoryGenerator"/>
<Method name="reformat"/>
<Bug pattern="DM_DEFAULT_ENCODING"/>
</Match>
<Match>
<Class name="com.github.benmanes.caffeine.cache.NodeFactoryGenerator"/>
<Method name="reformat"/>
<Bug pattern="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"/>
</Match>
<Match>
<Class name="com.github.benmanes.caffeine.cache.NodeFactoryGenerator"/>
<Method name="reformat"/>
<Bug pattern="DM_DEFAULT_ENCODING"/>
</Match>
<Match>
<Class name="~com.github.benmanes.caffeine.*Benchmark.*"/>
<Bug pattern="PREDICTABLE_RANDOM"/>
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ snakeyaml = "2.2"
sonarqube = "4.4.1.3373"
spotbugs-contrib = "7.6.0"
spotbugs-core = "4.8.0"
spotbugs-plugin = "6.0.0-beta.4"
spotbugs-plugin = "6.0.0-beta.5"
stream = "2.9.8"
tcache = "2.0.1"
testng = "7.8.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ spotbugs {
}

tasks.withType<SpotBugsTask>().configureEach {
inputs.property("version", libs.versions.spotbugs.core.get())
enabled = System.getProperties().containsKey("spotbugs")
group = "SpotBugs"
reports {
create("html") {
required = true
}
create("sarif") {
required = true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ public boolean contains(long item) {
}
indexing.getChain(hashFunc.fpaux, chainIndex, lastIndex);
int offset = itemsPerSet * hashFunc.fpaux.set;
indexing.chainStart += offset;
indexing.chainEnd += offset;
indexing.setChainStart(indexing.getChainStart() + offset);
indexing.setChainEnd(indexing.getChainEnd() + offset);

// Gil: I will carefully examine this function when I have time.
// As far as I understand it is working right now.
while (indexing.chainStart <= indexing.chainEnd) {
while (indexing.getChainStart() <= indexing.getChainEnd()) {
try {
if (cache[indexing.chainStart % cache.length] == hashFunc.fpaux.value) {
if (cache[indexing.getChainStart() % cache.length] == hashFunc.fpaux.value) {
return true;
}
indexing.chainStart++;
indexing.setChainStart(indexing.getChainStart() + 1);
} catch (RuntimeException e) {
System.out.println("length: " + cache.length + " Access: " + indexing.chainStart);
System.out.println("length: " + cache.length + " Access: " + indexing.getChainStart());
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ public int countItem(long item) {
}
indexing.getChain(hashFunc.fpaux, chainIndex, lastIndex);
int offset = itemsPerSet * hashFunc.fpaux.set;
indexing.chainStart += offset;
indexing.chainEnd += offset;
indexing.setChainStart(indexing.getChainStart() + offset);
indexing.setChainEnd(indexing.getChainEnd() + offset);

// Gil : I think some of these tests are, I till carefully examine this function when I have
// time. As far as I understand it is working right now.
int count = 0;
while (indexing.chainStart <= indexing.chainEnd) {
while (indexing.getChainStart() <= indexing.getChainEnd()) {
try {
if (cache[indexing.chainStart % cache.length] == hashFunc.fpaux.fingerprint) {
if (cache[indexing.getChainStart() % cache.length] == hashFunc.fpaux.fingerprint) {
count++;
}
indexing.chainStart++;
indexing.setChainStart(indexing.getChainStart() + 1);

} catch (RuntimeException e) {
System.out.println("length: " + cache.length + " Access: " + indexing.chainStart);
System.out.println("length: " + cache.length + " Access: " + indexing.getChainStart());
}
}
return count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ public boolean contains(long item) {
}
indexing.getChain(hashFunc.fpaux, chainIndex, lastIndex);
int offset = itemsPerSet * hashFunc.fpaux.set;
indexing.chainStart += offset;
indexing.chainEnd += offset;
indexing.setChainStart(indexing.getChainStart() + offset);
indexing.setChainEnd(indexing.getChainEnd() + offset);

// Gil : I think some of these tests are, I till carefully examine this function when I have
// time. As far as I understand it is working right now.
while (indexing.chainStart <= indexing.chainEnd) {
while (indexing.getChainStart() <= indexing.getChainEnd()) {
try {
if (cache[indexing.chainStart % cache.length] == hashFunc.fpaux.value) {
if (cache[indexing.getChainStart() % cache.length] == hashFunc.fpaux.value) {
return true;
}
indexing.chainStart++;
indexing.setChainStart(indexing.getChainStart() + 1);
} catch (RuntimeException e) {
System.out.println("length: " + cache.length + " Access: " + indexing.chainStart);
System.out.println("length: " + cache.length + " Access: " + indexing.getChainStart());
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
*/
final class TinySetIndexing {
// for performance - for functions that need to know both the start and the end of the chain.
public int chainStart;
public int chainEnd;
private int chainStart;
private int chainEnd;

public int getChainStart(HashedItem fpaux, long[] chainIndex, long[] isLastIndex) {
int requiredChainNumber = rank(chainIndex[fpaux.set], fpaux.chainId);
Expand Down Expand Up @@ -66,13 +66,13 @@ public int getChain(HashedItem fpaux, long[] chainIndex, long[] isLastIndex) {
currentOffset++;
tempisLastIndex >>>= 1;
}
chainStart = currentOffset;
setChainStart(currentOffset);

while ((tempisLastIndex & 1L) == 0) {
currentOffset++;
tempisLastIndex >>>= 1;
}
chainEnd = currentOffset;
setChainEnd(currentOffset);
return currentOffset;
}

Expand Down Expand Up @@ -136,4 +136,20 @@ public void removeItem(HashedItem fpaux, long[] chainIndex, long[] isLastIndex)
// update isLastIndex.
isLastIndex[fpaux.set] = shrinkOffset(isLastIndex[fpaux.set], chainStart);
}

public int getChainStart() {
return chainStart;
}

public void setChainStart(int chainStart) {
this.chainStart = chainStart;
}

public int getChainEnd() {
return chainEnd;
}

public void setChainEnd(int chainEnd) {
this.chainEnd = chainEnd;
}
}

0 comments on commit 0749c37

Please sign in to comment.