Skip to content

Commit b4112df

Browse files
authored
Fix Spotbugs check failed (apache#3836)
* fix spotbugs check failed * format code * install the package first * upgrade spotbugs version to 4.7.3.2 * upgrade javadoc plugin to 3.5.0 * upgrade javadoc plugin to 3.2.0 * format code * set maven version 3.8.7 * set all test maven version to 3.8.7 * fix failed CI * add test failure * address test failure * fix failed CI * format code
1 parent 20aad80 commit b4112df

File tree

7 files changed

+61
-6
lines changed

7 files changed

+61
-6
lines changed

.github/workflows/bk-ci.yml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,16 @@ jobs:
7979
distribution: 'temurin'
8080
java-version: 11
8181

82+
- name: Set up Maven
83+
uses: apache/pulsar-test-infra/setup-maven@master
84+
with:
85+
maven-version: 3.8.7
86+
8287
- name: Validate pull request
8388
if: steps.check_changes.outputs.docs_only != 'true'
84-
run: mvn clean -T 1C -B -nsu apache-rat:check checkstyle:check spotbugs:check package -Ddistributedlog -DskipTests -Dorg.slf4j.simpleLogger.defaultLogLevel=INFO
89+
run: |
90+
mvn -T 1C -B -nsu clean install -Ddistributedlog -DskipTests -Dorg.slf4j.simpleLogger.defaultLogLevel=INFO
91+
mvn -T 1C -B -nsu apache-rat:check checkstyle:check spotbugs:check package -Ddistributedlog -DskipTests -Dorg.slf4j.simpleLogger.defaultLogLevel=INFO
8592
8693
- name: Check license files
8794
if: steps.check_changes.outputs.docs_only != 'true'
@@ -152,6 +159,11 @@ jobs:
152159
distribution: 'temurin'
153160
java-version: 11
154161

162+
- name: Set up Maven
163+
uses: apache/pulsar-test-infra/setup-maven@master
164+
with:
165+
maven-version: 3.8.7
166+
155167
- name: Build
156168
run: |
157169
projects_list=
@@ -223,6 +235,11 @@ jobs:
223235
distribution: 'temurin'
224236
java-version: 11
225237

238+
- name: Set up Maven
239+
uses: apache/pulsar-test-infra/setup-maven@master
240+
with:
241+
maven-version: 3.8.7
242+
226243
- name: Build with Maven
227244
run: mvn -B -nsu clean install -Pdocker -DskipTests -Dorg.slf4j.simpleLogger.defaultLogLevel=INFO
228245

@@ -265,6 +282,11 @@ jobs:
265282
distribution: 'temurin'
266283
java-version: 8
267284

285+
- name: Set up Maven
286+
uses: apache/pulsar-test-infra/setup-maven@master
287+
with:
288+
maven-version: 3.8.7
289+
268290
- name: Build with Maven
269291
run: mvn -B -nsu clean install -DskipTests -Dorg.slf4j.simpleLogger.defaultLogLevel=INFO
270292

@@ -311,6 +333,11 @@ jobs:
311333
distribution: 'temurin'
312334
java-version: 11
313335

336+
- name: Set up Maven
337+
uses: apache/pulsar-test-infra/setup-maven@master
338+
with:
339+
maven-version: 3.8.7
340+
314341
- name: mvn package
315342
run: mvn -B -nsu clean package -DskipTests
316343

@@ -343,6 +370,11 @@ jobs:
343370
distribution: 'temurin'
344371
java-version: 11
345372

373+
- name: Set up Maven
374+
uses: apache/pulsar-test-infra/setup-maven@master
375+
with:
376+
maven-version: 3.8.7
377+
346378
- name: mvn package
347379
run: mvn -B -nsu clean package -DskipTests
348380

@@ -387,6 +419,11 @@ jobs:
387419
distribution: 'temurin'
388420
java-version: ${{ matrix.jdk_version }}
389421

422+
- name: Set up Maven
423+
uses: apache/pulsar-test-infra/setup-maven@master
424+
with:
425+
maven-version: 3.8.7
426+
390427
- name: Build with Maven
391428
run: mvn clean package -B -nsu -DskipBookKeeperServerTests -Dorg.slf4j.simpleLogger.defaultLogLevel=INFO
392429

@@ -422,6 +459,11 @@ jobs:
422459
with:
423460
java-version: 11
424461

462+
- name: Set up Maven
463+
uses: apache/pulsar-test-infra/setup-maven@master
464+
with:
465+
maven-version: 3.8.7
466+
425467
- name: run "clean install verify" to trigger dependency check
426468
# excluding dlfs because it includes hadoop lib with
427469
# CVEs that we cannot patch up anyways

bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingAddOp.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.apache.bookkeeper.proto.BookieProtocol.FLAG_RECOVERY_ADD;
2424

2525
import com.google.common.collect.ImmutableMap;
26+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2627
import io.netty.buffer.ByteBuf;
2728
import io.netty.util.Recycler;
2829
import io.netty.util.Recycler.Handle;
@@ -80,6 +81,7 @@ class PendingAddOp implements WriteCallback {
8081
boolean allowFailFast = false;
8182
List<BookieId> ensemble;
8283

84+
@SuppressFBWarnings("IS2_INCONSISTENT_SYNC")
8385
static PendingAddOp create(LedgerHandle lh, ClientContext clientCtx,
8486
List<BookieId> ensemble,
8587
ByteBuf payload, EnumSet<WriteFlag> writeFlags,

bookkeeper-server/src/main/java/org/apache/bookkeeper/util/PageCacheUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static void bestEffortRemoveFromPageCache(int fd, long offset, long len)
9595
}
9696
try {
9797
NATIVE_IO.posix_fadvise(fd, offset, len, POSIX_FADV_DONTNEED);
98-
} catch (Exception e) {
98+
} catch (Throwable e) {
9999
log.warn("Failed to perform posix_fadvise: {}", e.getMessage());
100100
fadvisePossible = false;
101101
}

bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/LedgerCacheTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.io.IOException;
3535
import java.util.ArrayList;
3636
import java.util.List;
37+
import java.util.concurrent.CountDownLatch;
3738
import java.util.concurrent.LinkedBlockingQueue;
3839
import java.util.concurrent.atomic.AtomicBoolean;
3940
import java.util.concurrent.atomic.AtomicInteger;
@@ -797,13 +798,17 @@ public void testSortedLedgerFlushFailure() throws Exception {
797798
// after flush failure, the bookie is set to readOnly
798799
assertTrue("Bookie is expected to be in Read mode", bookie.isReadOnly());
799800
// write fail
801+
CountDownLatch latch = new CountDownLatch(1);
800802
bookie.addEntry(generateEntry(1, 3), false, new BookkeeperInternalCallbacks.WriteCallback(){
801803
public void writeComplete(int rc, long ledgerId, long entryId, BookieId addr, Object ctx){
802-
LOG.info("fail write to bk");
803-
assertTrue(rc != OK);
804+
LOG.info("Write to bk succeed due to the bookie readOnly mode check is in the request parse step. "
805+
+ "In the addEntry step, we won't check bookie's mode");
806+
assertEquals(OK, rc);
807+
latch.countDown();
804808
}
805809

806810
}, null, "passwd".getBytes());
811+
latch.await();
807812
bookie.shutdown();
808813

809814
}

buildtools/src/main/resources/bookkeeper/findbugsExclude.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,11 @@
317317
<!-- generated code, we can't be held responsible for findbugs in it //-->
318318
<Class name="~.*\.TransformedRecord" />
319319
</Match>
320+
<!-- micro-benchmarks -->
321+
<Match>
322+
<!-- generated code, we can't be held responsible for findbugs in it //-->
323+
<Class name="~org\.apache\.bookkeeper\.bookie\.generated.*" />
324+
</Match>
320325
<Match>
321326
<!-- it is safe to store external bytes reference here. //-->
322327
<Class name="org.apache.distributedlog.messaging.PartitionedMultiWriter" />

microbenchmarks/src/main/java/org/apache/bookkeeper/bookie/GroupSortBenchmark.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import java.util.Arrays;
2525
import java.util.Random;
26+
import java.util.concurrent.ThreadLocalRandom;
2627
import java.util.concurrent.TimeUnit;
2728
import org.apache.bookkeeper.bookie.storage.ldb.ArrayGroupSort;
2829
import org.openjdk.jmh.annotations.Benchmark;
@@ -55,7 +56,7 @@ public static class TestState {
5556
private long[] items;
5657

5758
public TestState() {
58-
Random r = new Random();
59+
Random r = ThreadLocalRandom.current();
5960
for (int i = 0; i < (N * 4); i++) {
6061
randomItems[i] = r.nextLong();
6162
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
<os-maven-plugin.version>1.4.1.Final</os-maven-plugin.version>
206206
<protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version>
207207
<puppycrawl.checkstyle.version>9.3</puppycrawl.checkstyle.version>
208-
<spotbugs-maven-plugin.version>4.6.0.0</spotbugs-maven-plugin.version>
208+
<spotbugs-maven-plugin.version>4.7.3.2</spotbugs-maven-plugin.version>
209209
<forkCount.variable>1</forkCount.variable>
210210
<servlet-api.version>4.0.0</servlet-api.version>
211211
<rxjava.version>3.0.1</rxjava.version>

0 commit comments

Comments
 (0)