adoroszlai opened a new pull request, #9458: URL: https://github.com/apache/ozone/pull/9458
## What changes were proposed in this pull request? - Replace all remaining `Preconditions.checkNotNull` with `Objects.requireNonNull`. - Add message where missing in statements being changed. - Combine simple assignments with the check. - Add checkstyle rule to prevent any new `checkNotNull` usage being introduced. https://issues.apache.org/jira/browse/HDDS-14090 ## How was this patch tested? Introduced some violations formatted in various ways (removal of unused imports omitted here): ```diff --- hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java +++ hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java @@ -636,7 +636,7 @@ public static long getTime() { */ public static void validatePath(Path path, Path ancestor) { Objects.requireNonNull(path, "Path should not be null"); - Objects.requireNonNull(ancestor, "Ancestor should not be null"); + Preconditions.checkNotNull(ancestor, "Ancestor should not be null"); Preconditions.checkArgument( path.normalize().startsWith(ancestor.normalize()), "Path %s should be a descendant of %s", path, ancestor); --- hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/ChunkBufferImplWithByteBufferList.java +++ hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/ChunkBufferImplWithByteBufferList.java @@ -50,7 +49,8 @@ public class ChunkBufferImplWithByteBufferList implements ChunkBuffer { private int currentIndex; ChunkBufferImplWithByteBufferList(List<ByteBuffer> buffers) { - Objects.requireNonNull(buffers, "buffers == null"); + Preconditions + .checkNotNull(buffers, "buffers == null"); this.buffers = !buffers.isEmpty() ? ImmutableList.copyOf(buffers) : EMPTY_BUFFER; this.limit = buffers.stream().mapToInt(ByteBuffer::limit).sum(); --- hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/IncrementalChunkBuffer.java +++ hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/IncrementalChunkBuffer.java @@ -255,7 +254,9 @@ public ChunkBuffer duplicate(int newPosition, int newLimit) { private ByteBuffer duplicate(int i, int pos, int lim) { final ByteBuffer ith = getAtIndex(i); - Objects.requireNonNull(ith, () -> "buffers[" + i + "] == null"); + Preconditions + . + checkNotNull(ith, () -> "buffers[" + i + "] == null"); final ByteBuffer b = ith.duplicate(); b.position(pos).limit(lim); return b; --- hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/utils/BufferUtils.java +++ hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/utils/BufferUtils.java @@ -17,6 +17,8 @@ package org.apache.hadoop.ozone.common.utils; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.base.Preconditions; import java.io.IOException; import java.nio.ByteBuffer; @@ -117,6 +119,7 @@ public static ByteString concatByteStrings(List<ByteString> byteStrings) { */ public static long getBuffersLen(List<ByteString> buffers) { long length = 0; + checkNotNull(buffers); for (ByteString buffer : buffers) { length += buffer.size(); } ``` and verified that checkstyle detects them: ``` hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java 639: Use Objects.requireNonNull instead of Preconditions.checkNotNull hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/IncrementalChunkBuffer.java 257: Use Objects.requireNonNull instead of Preconditions.checkNotNull hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/ChunkBufferImplWithByteBufferList.java 52: Use Objects.requireNonNull instead of Preconditions.checkNotNull hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/utils/BufferUtils.java 20: Use Objects.requireNonNull instead of Preconditions.checkNotNull ``` CI: https://github.com/adoroszlai/ozone/actions/runs/20007542569 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
