From fda0721a709e3ad6232edaeb715efc2feb2bb28f Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 8 May 2024 18:45:20 +0200 Subject: [PATCH] Enable checkstyle Fix the few remaining warnings and enable checkstyle. Change-Id: I6eaeaefe921633d76dfa6283d0685a3c53320b95 Signed-off-by: Robert Varga --- atomix-storage/pom.xml | 1 - .../atomix/storage/journal/ByteBufMapper.java | 2 +- .../storage/journal/JournalSegment.java | 2 +- .../journal/JournalSegmentDescriptor.java | 5 +++ .../storage/journal/MappedFileAccess.java | 11 ++--- .../journal/SegmentedByteBufJournal.java | 9 ++++ .../storage/journal/AbstractJournalTest.java | 44 +++++++++---------- 7 files changed, 44 insertions(+), 30 deletions(-) diff --git a/atomix-storage/pom.xml b/atomix-storage/pom.xml index bb07137137..9353382deb 100644 --- a/atomix-storage/pom.xml +++ b/atomix-storage/pom.xml @@ -29,7 +29,6 @@ bundle - true false diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufMapper.java b/atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufMapper.java index e29dbcb60a..fa477aa554 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufMapper.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufMapper.java @@ -32,7 +32,7 @@ public interface ByteBufMapper { * @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}. diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegment.java b/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegment.java index bab668ffd6..b842d95e24 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegment.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegment.java @@ -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 diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentDescriptor.java b/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentDescriptor.java index e64110e675..74fae69872 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentDescriptor.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentDescriptor.java @@ -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; diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/MappedFileAccess.java b/atomix-storage/src/main/java/io/atomix/storage/journal/MappedFileAccess.java index 77597642d0..9966aebd7f 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/MappedFileAccess.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/MappedFileAccess.java @@ -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(); + } }); } diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedByteBufJournal.java b/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedByteBufJournal.java index 2afc434f33..e0be413734 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedByteBufJournal.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedByteBufJournal.java @@ -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; diff --git a/atomix-storage/src/test/java/io/atomix/storage/journal/AbstractJournalTest.java b/atomix-storage/src/test/java/io/atomix/storage/journal/AbstractJournalTest.java index d5227b83cb..5cb516b7b6 100644 --- a/atomix-storage/src/test/java/io/atomix/storage/journal/AbstractJournalTest.java +++ b/atomix-storage/src/test/java/io/atomix/storage/journal/AbstractJournalTest.java @@ -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 journal = createJournal()) { - JournalWriter writer = journal.writer(); - JournalReader 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()); -- 2.36.6