Enable checkstyle 64/111664/4
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 8 May 2024 16:45:20 +0000 (18:45 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 9 May 2024 15:36:19 +0000 (17:36 +0200)
Fix the few remaining warnings and enable checkstyle.

Change-Id: I6eaeaefe921633d76dfa6283d0685a3c53320b95
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
atomix-storage/pom.xml
atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufMapper.java
atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegment.java
atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentDescriptor.java
atomix-storage/src/main/java/io/atomix/storage/journal/MappedFileAccess.java
atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedByteBufJournal.java
atomix-storage/src/test/java/io/atomix/storage/journal/AbstractJournalTest.java

index bb0713713758333c2404b7528e83852d593771d5..9353382deb90f0611b0faf2eedd39e771df72b07 100644 (file)
@@ -29,7 +29,6 @@
   <packaging>bundle</packaging>
 
   <properties>
-    <odlparent.checkstyle.skip>true</odlparent.checkstyle.skip>
     <odlparent.spotbugs.enforce>false</odlparent.spotbugs.enforce>
   </properties>
 
index e29dbcb60a5bf586f09975e53c40fb7c6baa57e2..fa477aa554de990e17c9796322352313ce44868d 100644 (file)
@@ -32,7 +32,7 @@ public interface ByteBufMapper<T> {
      * @param bytes entry bytes
      * @return resulting object
      */
-    T bytesToObject(final long index, ByteBuf bytes);
+    T bytesToObject(long index, ByteBuf bytes);
 
     /**
      * Converts an object into a series of bytes in the specified {@link ByteBuf}.
index bab668ffd6982a6a3f2ec07bfef3cc5c9b904f35..b842d95e2495460770024018c361e8a5f7fc66be 100644 (file)
@@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory;
  */
 final class JournalSegment {
     /**
-     * Encapsulation of a {@link JournalSegment}'s state;
+     * Encapsulation of a {@link JournalSegment}'s state.
      */
     sealed interface State {
         // Marker interface
index e64110e675919e4ce65ca164f69f2b61ee45b97f..74fae698726e1b59beb125ab4f1b3392b9b86276 100644 (file)
@@ -225,6 +225,7 @@ public record JournalSegmentDescriptor(
          * @param id The segment identifier.
          * @return The segment descriptor builder.
          */
+        @SuppressWarnings("checkstyle:hiddenField")
         public Builder withId(final long id) {
             this.id = id;
             return this;
@@ -236,6 +237,7 @@ public record JournalSegmentDescriptor(
          * @param index The segment starting index.
          * @return The segment descriptor builder.
          */
+        @SuppressWarnings("checkstyle:hiddenField")
         public Builder withIndex(final long index) {
             this.index = index;
             return this;
@@ -247,6 +249,7 @@ public record JournalSegmentDescriptor(
          * @param maxSegmentSize The maximum count of the segment.
          * @return The segment descriptor builder.
          */
+        @SuppressWarnings("checkstyle:hiddenField")
         public Builder withMaxSegmentSize(final int maxSegmentSize) {
             this.maxSegmentSize = maxSegmentSize;
             return this;
@@ -260,6 +263,7 @@ public record JournalSegmentDescriptor(
          * @deprecated since 3.0.2
          */
         @Deprecated
+        @SuppressWarnings("checkstyle:hiddenField")
         public Builder withMaxEntries(final int maxEntries) {
             this.maxEntries = maxEntries;
             return this;
@@ -271,6 +275,7 @@ public record JournalSegmentDescriptor(
          * @param updated Epoch milliseconds
          * @return The segment descriptor builder.
          */
+        @SuppressWarnings("checkstyle:hiddenField")
         public Builder withUpdated(final long updated) {
             this.updated = updated;
             return this;
index 77597642d0bb3cc8eeb63c79608877d73e3b3869..9966aebd7fce2667643b46cd1d98907d1b8f7c1a 100644 (file)
@@ -40,13 +40,14 @@ final class MappedFileAccess extends FileAccess {
     }
 
     @Override
+    @SuppressWarnings("checkstyle:avoidHidingCauseException")
     MappedFileWriter newFileWriter() {
         return new MappedFileWriter(file, maxEntrySize, mappedBuffer.slice(), () -> {
-           try {
-               mappedBuffer.force();
-           } catch (UncheckedIOException e) {
-               throw e.getCause();
-           }
+            try {
+                mappedBuffer.force();
+            } catch (UncheckedIOException e) {
+                throw e.getCause();
+            }
         });
     }
 
index 2afc434f33d78345a5995cdb3123bd99ec85395f..e0be4137347a92444f4496eb87afa917f96e6a9c 100644 (file)
@@ -478,6 +478,7 @@ public final class SegmentedByteBufJournal implements ByteBufJournal {
          * @param name The journal name.
          * @return The builder instance
          */
+        @SuppressWarnings("checkstyle:hiddenField")
         public Builder withName(final String name) {
             this.name = requireNonNull(name, "name cannot be null");
             return this;
@@ -489,6 +490,7 @@ public final class SegmentedByteBufJournal implements ByteBufJournal {
          * @param storageLevel The storage level.
          * @return The builder instance
          */
+        @SuppressWarnings("checkstyle:hiddenField")
         public Builder withStorageLevel(final StorageLevel storageLevel) {
             this.storageLevel = requireNonNull(storageLevel, "storageLevel cannot be null");
             return this;
@@ -501,6 +503,7 @@ public final class SegmentedByteBufJournal implements ByteBufJournal {
          * @return The builder instance
          * @throws NullPointerException If the {@code directory} is {@code null}
          */
+        @SuppressWarnings("checkstyle:hiddenField")
         public Builder withDirectory(final String directory) {
             return withDirectory(new File(requireNonNull(directory, "directory cannot be null")));
         }
@@ -512,6 +515,7 @@ public final class SegmentedByteBufJournal implements ByteBufJournal {
          * @return The builder instance
          * @throws NullPointerException If the {@code directory} is {@code null}
          */
+        @SuppressWarnings("checkstyle:hiddenField")
         public Builder withDirectory(final File directory) {
             this.directory = requireNonNull(directory, "directory cannot be null");
             return this;
@@ -525,6 +529,7 @@ public final class SegmentedByteBufJournal implements ByteBufJournal {
          * @return The builder instance
          * @throws IllegalArgumentException If the {@code maxSegmentSize} is not positive
          */
+        @SuppressWarnings("checkstyle:hiddenField")
         public Builder withMaxSegmentSize(final int maxSegmentSize) {
             checkArgument(maxSegmentSize > JournalSegmentDescriptor.BYTES,
                 "maxSegmentSize must be greater than " + JournalSegmentDescriptor.BYTES);
@@ -539,6 +544,7 @@ public final class SegmentedByteBufJournal implements ByteBufJournal {
          * @return the builder instance
          * @throws IllegalArgumentException if the {@code maxEntrySize} is not positive
          */
+        @SuppressWarnings("checkstyle:hiddenField")
         public Builder withMaxEntrySize(final int maxEntrySize) {
             checkArgument(maxEntrySize > 0, "maxEntrySize must be positive");
             this.maxEntrySize = maxEntrySize;
@@ -563,6 +569,7 @@ public final class SegmentedByteBufJournal implements ByteBufJournal {
          * @deprecated This option has no effect and is scheduled for removal.
          */
         @Deprecated(forRemoval = true, since = "9.0.3")
+        @SuppressWarnings("checkstyle:hiddenField")
         public Builder withMaxEntriesPerSegment(final int maxEntriesPerSegment) {
             checkArgument(maxEntriesPerSegment > 0, "max entries per segment must be positive");
             checkArgument(maxEntriesPerSegment <= DEFAULT_MAX_ENTRIES_PER_SEGMENT,
@@ -582,6 +589,7 @@ public final class SegmentedByteBufJournal implements ByteBufJournal {
          * @return the builder instance
          * @throws IllegalArgumentException if the density is not between 0 and 1
          */
+        @SuppressWarnings("checkstyle:hiddenField")
         public Builder withIndexDensity(final double indexDensity) {
             checkArgument(indexDensity > 0 && indexDensity < 1, "index density must be between 0 and 1");
             this.indexDensity = indexDensity;
@@ -611,6 +619,7 @@ public final class SegmentedByteBufJournal implements ByteBufJournal {
          * @param flushOnCommit Whether to flush buffers to disk when entries are committed to a segment.
          * @return The builder instance
          */
+        @SuppressWarnings("checkstyle:hiddenField")
         public Builder withFlushOnCommit(final boolean flushOnCommit) {
             this.flushOnCommit = flushOnCommit;
             return this;
index d5227b83cbcd1a8610492030276e5d15f0560bda..5cb516b7b668b425269d5d8622309eff1f5d96ce 100644 (file)
@@ -101,8 +101,8 @@ public abstract class AbstractJournalTest {
     @Test
     public void testWriteRead() throws Exception {
         try (var journal = createJournal()) {
-            var writer = journal.writer();
-            var reader = journal.openReader(1);
+            final var writer = journal.writer();
+            final var reader = journal.openReader(1);
 
             // Append a couple entries.
             assertEquals(1, writer.getNextIndex());
@@ -129,51 +129,51 @@ public abstract class AbstractJournalTest {
             assertNoNext(reader);
 
             // Test opening a new reader and reading from the journal.
-            reader = journal.openReader(1);
-            entry1 = assertNext(reader);
+            final var reader2 = journal.openReader(1);
+            entry1 = assertNext(reader2);
             assertEquals(1, entry1.index());
 
-            assertEquals(2, reader.getNextIndex());
-            entry2 = assertNext(reader);
+            assertEquals(2, reader2.getNextIndex());
+            entry2 = assertNext(reader2);
             assertEquals(2, entry2.index());
-            assertNoNext(reader);
+            assertNoNext(reader2);
 
             // Reset the reader.
-            reader.reset();
+            reader2.reset();
 
             // Test opening a new reader and reading from the journal.
-            reader = journal.openReader(1);
-            entry1 = assertNext(reader);
+            final var reader3 = journal.openReader(1);
+            entry1 = assertNext(reader3);
             assertEquals(1, entry1.index());
 
-            assertEquals(2, reader.getNextIndex());
-            entry2 = assertNext(reader);
+            assertEquals(2, reader3.getNextIndex());
+            entry2 = assertNext(reader3);
             assertEquals(2, entry2.index());
-            assertNoNext(reader);
+            assertNoNext(reader3);
 
             // Truncate the journal and write a different entry.
             writer.reset(2);
             assertEquals(2, writer.getNextIndex());
             writer.append(ENTRY);
-            reader.reset(2);
-            indexed = assertNext(reader);
+            reader3.reset(2);
+            indexed = assertNext(reader3);
             assertEquals(2, indexed.index());
 
             // Reset the reader to a specific index and read the last entry again.
-            reader.reset(2);
+            reader3.reset(2);
 
-            assertEquals(2, reader.getNextIndex());
-            entry2 = assertNext(reader);
+            assertEquals(2, reader3.getNextIndex());
+            entry2 = assertNext(reader3);
             assertEquals(2, entry2.index());
-            assertNoNext(reader);
+            assertNoNext(reader3);
         }
     }
 
     @Test
     public void testResetTruncateZero() throws Exception {
-        try (SegmentedJournal<TestEntry> journal = createJournal()) {
-            JournalWriter<TestEntry> writer = journal.writer();
-            JournalReader<TestEntry> reader = journal.openReader(1);
+        try (var journal = createJournal()) {
+            final var writer = journal.writer();
+            final var reader = journal.openReader(1);
 
             assertEquals(0, journal.lastIndex());
             assertEquals(1, writer.getNextIndex());