From e8dfb71eff8157069a27e2d21eed5e3e2c87aeed Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 2 Mar 2023 12:05:49 +0100 Subject: [PATCH] Enable modernizer in atomix-storage There are only a few checkNotNull() violations, migrate them and enable modernizer. JIRA: CONTROLLER-2071 Change-Id: I8182ca3963e69a9029aa2ba458b76d16c4674d8a Signed-off-by: Robert Varga --- third-party/atomix/storage/pom.xml | 1 - .../journal/JournalSegmentDescriptor.java | 4 ++-- .../storage/journal/JournalSegmentFile.java | 8 ++++---- .../storage/journal/SegmentedJournal.java | 20 +++++++++---------- .../io/atomix/utils/serializer/Namespace.java | 6 +++--- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/third-party/atomix/storage/pom.xml b/third-party/atomix/storage/pom.xml index ee6aa905a3..51f3f98196 100644 --- a/third-party/atomix/storage/pom.xml +++ b/third-party/atomix/storage/pom.xml @@ -30,7 +30,6 @@ true - true true diff --git a/third-party/atomix/storage/src/main/java/io/atomix/storage/journal/JournalSegmentDescriptor.java b/third-party/atomix/storage/src/main/java/io/atomix/storage/journal/JournalSegmentDescriptor.java index 71ad15e398..28072cec4d 100644 --- a/third-party/atomix/storage/src/main/java/io/atomix/storage/journal/JournalSegmentDescriptor.java +++ b/third-party/atomix/storage/src/main/java/io/atomix/storage/journal/JournalSegmentDescriptor.java @@ -20,7 +20,7 @@ import com.google.common.annotations.VisibleForTesting; import java.nio.ByteBuffer; import static com.google.common.base.MoreObjects.toStringHelper; -import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; /** * Stores information about a {@link JournalSegment} of the log. @@ -226,7 +226,7 @@ public final class JournalSegmentDescriptor { private final ByteBuffer buffer; private Builder(ByteBuffer buffer) { - this.buffer = checkNotNull(buffer, "buffer cannot be null"); + this.buffer = requireNonNull(buffer, "buffer cannot be null"); buffer.putInt(VERSION_POSITION, VERSION); } diff --git a/third-party/atomix/storage/src/main/java/io/atomix/storage/journal/JournalSegmentFile.java b/third-party/atomix/storage/src/main/java/io/atomix/storage/journal/JournalSegmentFile.java index 9fe7f12ed5..5fe226d3bb 100644 --- a/third-party/atomix/storage/src/main/java/io/atomix/storage/journal/JournalSegmentFile.java +++ b/third-party/atomix/storage/src/main/java/io/atomix/storage/journal/JournalSegmentFile.java @@ -17,7 +17,7 @@ package io.atomix.storage.journal; import java.io.File; -import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; /** * Segment file utility. @@ -47,8 +47,8 @@ public final class JournalSegmentFile { * @throws NullPointerException if {@code file} is null */ public static boolean isSegmentFile(String journalName, String fileName) { - checkNotNull(journalName, "journalName cannot be null"); - checkNotNull(fileName, "fileName cannot be null"); + requireNonNull(journalName, "journalName cannot be null"); + requireNonNull(fileName, "fileName cannot be null"); int partSeparator = fileName.lastIndexOf(PART_SEPARATOR); int extensionSeparator = fileName.lastIndexOf(EXTENSION_SEPARATOR); @@ -73,7 +73,7 @@ public final class JournalSegmentFile { * Creates a segment file for the given directory, log name, segment ID, and segment version. */ static File createSegmentFile(String name, File directory, long id) { - return new File(directory, String.format("%s-%d.log", checkNotNull(name, "name cannot be null"), id)); + return new File(directory, String.format("%s-%d.log", requireNonNull(name, "name cannot be null"), id)); } /** diff --git a/third-party/atomix/storage/src/main/java/io/atomix/storage/journal/SegmentedJournal.java b/third-party/atomix/storage/src/main/java/io/atomix/storage/journal/SegmentedJournal.java index 4fb4a7459f..419a67e5fb 100644 --- a/third-party/atomix/storage/src/main/java/io/atomix/storage/journal/SegmentedJournal.java +++ b/third-party/atomix/storage/src/main/java/io/atomix/storage/journal/SegmentedJournal.java @@ -35,8 +35,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import static java.util.Objects.requireNonNull; /** * Segmented journal. @@ -83,10 +83,10 @@ public class SegmentedJournal implements Journal { int maxEntriesPerSegment, double indexDensity, boolean flushOnCommit) { - this.name = checkNotNull(name, "name cannot be null"); - this.storageLevel = checkNotNull(storageLevel, "storageLevel cannot be null"); - this.directory = checkNotNull(directory, "directory cannot be null"); - this.namespace = checkNotNull(namespace, "namespace cannot be null"); + this.name = requireNonNull(name, "name cannot be null"); + this.storageLevel = requireNonNull(storageLevel, "storageLevel cannot be null"); + this.directory = requireNonNull(directory, "directory cannot be null"); + this.namespace = requireNonNull(namespace, "namespace cannot be null"); this.maxSegmentSize = maxSegmentSize; this.maxEntrySize = maxEntrySize; this.maxEntriesPerSegment = maxEntriesPerSegment; @@ -696,7 +696,7 @@ public class SegmentedJournal implements Journal { * @return The storage builder. */ public Builder withName(String name) { - this.name = checkNotNull(name, "name cannot be null"); + this.name = requireNonNull(name, "name cannot be null"); return this; } @@ -709,7 +709,7 @@ public class SegmentedJournal implements Journal { * @return The storage builder. */ public Builder withStorageLevel(StorageLevel storageLevel) { - this.storageLevel = checkNotNull(storageLevel, "storageLevel cannot be null"); + this.storageLevel = requireNonNull(storageLevel, "storageLevel cannot be null"); return this; } @@ -723,7 +723,7 @@ public class SegmentedJournal implements Journal { * @throws NullPointerException If the {@code directory} is {@code null} */ public Builder withDirectory(String directory) { - return withDirectory(new File(checkNotNull(directory, "directory cannot be null"))); + return withDirectory(new File(requireNonNull(directory, "directory cannot be null"))); } /** @@ -736,7 +736,7 @@ public class SegmentedJournal implements Journal { * @throws NullPointerException If the {@code directory} is {@code null} */ public Builder withDirectory(File directory) { - this.directory = checkNotNull(directory, "directory cannot be null"); + this.directory = requireNonNull(directory, "directory cannot be null"); return this; } @@ -747,7 +747,7 @@ public class SegmentedJournal implements Journal { * @return The journal builder. */ public Builder withNamespace(Namespace namespace) { - this.namespace = checkNotNull(namespace, "namespace cannot be null"); + this.namespace = requireNonNull(namespace, "namespace cannot be null"); return this; } diff --git a/third-party/atomix/storage/src/main/java/io/atomix/utils/serializer/Namespace.java b/third-party/atomix/storage/src/main/java/io/atomix/utils/serializer/Namespace.java index 6ebd044c9d..1d16920a67 100644 --- a/third-party/atomix/storage/src/main/java/io/atomix/utils/serializer/Namespace.java +++ b/third-party/atomix/storage/src/main/java/io/atomix/utils/serializer/Namespace.java @@ -39,7 +39,7 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; -import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; import static org.slf4j.LoggerFactory.getLogger; /** @@ -175,7 +175,7 @@ public final class Namespace implements KryoFactory, KryoPool { * @return this */ public Builder register(Serializer serializer, final Class... classes) { - types.add(Pair.of(classes, checkNotNull(serializer))); + types.add(Pair.of(classes, requireNonNull(serializer))); return this; } @@ -279,7 +279,7 @@ public final class Namespace implements KryoFactory, KryoPool { this.registrationRequired = registrationRequired; this.classLoader = classLoader; this.compatible = compatible; - this.friendlyName = checkNotNull(friendlyName); + this.friendlyName = requireNonNull(friendlyName); } /** -- 2.36.6