From 12a67a3038f4372576ebaa872e8bb0d95e966c1f Mon Sep 17 00:00:00 2001 From: Jeff Yemin Date: Wed, 22 May 2024 10:26:40 -0400 Subject: [PATCH 1/4] Upgrade to Spotbugs 6.0.15 * Exclude CT_CONSTRUCTOR_THROW * Exclude PA_PUBLIC_PRIMITIVE_ATTRIBUTE * Add assertion to handle NP warning JAVA-5480 --- build.gradle | 2 +- config/spotbugs/exclude.xml | 11 +++++++++++ .../connection/AbstractMultiServerCluster.java | 4 +++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index aa0dd05ed38..a360408241a 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ buildscript { } dependencies { classpath 'com.netflix.nebula:gradle-extra-configurations-plugin:7.0.0' - classpath "com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.13" + classpath "com.github.spotbugs.snom:spotbugs-gradle-plugin:6.0.15" classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:5.1.2' // Scala plugins diff --git a/config/spotbugs/exclude.xml b/config/spotbugs/exclude.xml index fb0e4e9ec0e..79df7379ea1 100644 --- a/config/spotbugs/exclude.xml +++ b/config/spotbugs/exclude.xml @@ -18,6 +18,17 @@ for the mapping from SpotBugs rank to verbal labels. --> + + + + + + + + + + + diff --git a/driver-core/src/main/com/mongodb/internal/connection/AbstractMultiServerCluster.java b/driver-core/src/main/com/mongodb/internal/connection/AbstractMultiServerCluster.java index 5b6fa8f56fe..61ca40ba495 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/AbstractMultiServerCluster.java +++ b/driver-core/src/main/com/mongodb/internal/connection/AbstractMultiServerCluster.java @@ -18,6 +18,7 @@ import com.mongodb.MongoException; import com.mongodb.ServerAddress; +import com.mongodb.assertions.Assertions; import com.mongodb.connection.ClusterDescription; import com.mongodb.connection.ClusterId; import com.mongodb.connection.ClusterSettings; @@ -38,6 +39,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import static com.mongodb.assertions.Assertions.assertNotNull; import static com.mongodb.assertions.Assertions.isTrue; import static com.mongodb.connection.ClusterConnectionMode.MULTIPLE; import static com.mongodb.connection.ClusterType.UNKNOWN; @@ -234,7 +236,7 @@ private boolean handleReplicaSetMemberChanged(final ServerDescription newDescrip } if (replicaSetName == null) { - replicaSetName = newDescription.getSetName(); + replicaSetName = assertNotNull(newDescription.getSetName()); } if (!replicaSetName.equals(newDescription.getSetName())) { From 5fb00af4e1178dff10bdd777bf8cc1ce8dcd0f41 Mon Sep 17 00:00:00 2001 From: Jeff Yemin Date: Wed, 22 May 2024 10:43:16 -0400 Subject: [PATCH 2/4] Fix import --- .../mongodb/internal/connection/AbstractMultiServerCluster.java | 1 - 1 file changed, 1 deletion(-) diff --git a/driver-core/src/main/com/mongodb/internal/connection/AbstractMultiServerCluster.java b/driver-core/src/main/com/mongodb/internal/connection/AbstractMultiServerCluster.java index 61ca40ba495..272442a190e 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/AbstractMultiServerCluster.java +++ b/driver-core/src/main/com/mongodb/internal/connection/AbstractMultiServerCluster.java @@ -18,7 +18,6 @@ import com.mongodb.MongoException; import com.mongodb.ServerAddress; -import com.mongodb.assertions.Assertions; import com.mongodb.connection.ClusterDescription; import com.mongodb.connection.ClusterId; import com.mongodb.connection.ClusterSettings; From 34cb5dc703e8a4cc079f00f2bcb27b08c3668ef2 Mon Sep 17 00:00:00 2001 From: Jeff Yemin Date: Wed, 22 May 2024 10:54:59 -0400 Subject: [PATCH 3/4] Added ranks and a comment on how to find them --- build.gradle | 3 ++- config/spotbugs/exclude.xml | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index a360408241a..93dd99ea3a4 100644 --- a/build.gradle +++ b/build.gradle @@ -347,8 +347,9 @@ configure(javaCodeCheckedProjects) { spotbugsMain { reports { - xml.enabled = project.buildingWith('xmlReports.enabled') + xml.enabled = true html.enabled = !project.buildingWith('xmlReports.enabled') + sarif.enabled = true } } diff --git a/config/spotbugs/exclude.xml b/config/spotbugs/exclude.xml index 79df7379ea1..1ef5de78bf5 100644 --- a/config/spotbugs/exclude.xml +++ b/config/spotbugs/exclude.xml @@ -14,17 +14,25 @@ ~ limitations under the License. --> - - + - + From 0775ec17f09391e0cf834e883f890d503b065fba Mon Sep 17 00:00:00 2001 From: Jeff Yemin Date: Wed, 22 May 2024 14:11:15 -0400 Subject: [PATCH 4/4] Revert errant change --- build.gradle | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 93dd99ea3a4..a360408241a 100644 --- a/build.gradle +++ b/build.gradle @@ -347,9 +347,8 @@ configure(javaCodeCheckedProjects) { spotbugsMain { reports { - xml.enabled = true + xml.enabled = project.buildingWith('xmlReports.enabled') html.enabled = !project.buildingWith('xmlReports.enabled') - sarif.enabled = true } }