From 7c802c42dc6ed3369e90e7acbbe308db98f3a316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Elek?= Date: Mon, 18 Feb 2019 18:39:57 +0100 Subject: [PATCH] HDDS-1129. Fix findbug/checkstyle errors hdds projects. Contributed by Elek, Marton. --- .../hadoop/hdds/scm/storage/BlockInputStream.java | 15 +++++++++------ hadoop-hdds/pom.xml | 7 +++++++ hadoop-hdds/server-scm/pom.xml | 5 +++++ .../hdds/scm/pipeline/PipelineStateMap.java | 8 +++++--- .../hdds/scm/pipeline/RatisPipelineProvider.java | 4 ++++ .../ozone/om/ratis/OzoneManagerRatisServer.java | 3 ++- 6 files changed, 32 insertions(+), 10 deletions(-) diff --git a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockInputStream.java b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockInputStream.java index d53d20e1a79..0e2c4712434 100644 --- a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockInputStream.java +++ b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockInputStream.java @@ -109,7 +109,8 @@ public synchronized int read() int dataout = EOF; if (available == EOF) { - Preconditions.checkState (buffers == null); //should have released by now, see below + Preconditions + .checkState(buffers == null); //should have released by now, see below } else { dataout = Byte.toUnsignedInt(buffers.get(bufferIndex).get()); } @@ -149,7 +150,8 @@ public synchronized int read(byte[] b, int off, int len) throws IOException { while (len > 0) { int available = prepareRead(len); if (available == EOF) { - Preconditions.checkState(buffers == null); //should have been released by now + Preconditions + .checkState(buffers == null); //should have been released by now return total != 0 ? total : EOF; } buffers.get(bufferIndex).get(b, off + total, available); @@ -167,7 +169,7 @@ public synchronized int read(byte[] b, int off, int len) throws IOException { } /** - * Determines if all data in the stream has been consumed + * Determines if all data in the stream has been consumed. * * @return true if EOF, false if more data is available */ @@ -176,8 +178,9 @@ private boolean blockStreamEOF() { return false; } else { // if there are any chunks, we better be at the last chunk for EOF - Preconditions.checkState (((chunks == null) || chunks.isEmpty() || - chunkIndex == (chunks.size() - 1)), "EOF detected, but not at the last chunk"); + Preconditions.checkState(((chunks == null) || chunks.isEmpty() || + chunkIndex == (chunks.size() - 1)), + "EOF detected, but not at the last chunk"); return true; } } @@ -247,7 +250,7 @@ private boolean buffersHaveData() { if (buffersRemaining()) { // move to next available buffer ++bufferIndex; - Preconditions.checkState (bufferIndex < buffers.size()); + Preconditions.checkState(bufferIndex < buffers.size()); } else { // no more buffers remaining break; diff --git a/hadoop-hdds/pom.xml b/hadoop-hdds/pom.xml index a4d77ac5264..e7cced800b7 100644 --- a/hadoop-hdds/pom.xml +++ b/hadoop-hdds/pom.xml @@ -189,6 +189,13 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> ${junit.jupiter.version} test + + + com.google.code.findbugs + findbugs + 3.0.1 + provided + diff --git a/hadoop-hdds/server-scm/pom.xml b/hadoop-hdds/server-scm/pom.xml index aff0d29b095..33534cd4f8f 100644 --- a/hadoop-hdds/server-scm/pom.xml +++ b/hadoop-hdds/server-scm/pom.xml @@ -100,6 +100,11 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> org.bouncycastle bcprov-jdk15on + + com.google.code.findbugs + findbugs + provided + diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelineStateMap.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelineStateMap.java index 2b6c61b1e84..8e0b62bacc9 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelineStateMap.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelineStateMap.java @@ -18,6 +18,7 @@ package org.apache.hadoop.hdds.scm.pipeline; import com.google.common.base.Preconditions; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor; import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType; @@ -328,13 +329,13 @@ Pipeline updatePipelineState(PipelineID pipelineID, PipelineState state) return updatedPipeline; } - private class PipelineQuery { + private static class PipelineQuery { private ReplicationType type; private ReplicationFactor factor; PipelineQuery(ReplicationType type, ReplicationFactor factor) { - this.type = type; - this.factor = factor; + this.type = Preconditions.checkNotNull(type); + this.factor = Preconditions.checkNotNull(factor); } PipelineQuery(Pipeline pipeline) { @@ -343,6 +344,7 @@ private class PipelineQuery { } @Override + @SuppressFBWarnings("NP_EQUALS_SHOULD_HANDLE_NULL_ARGUMENT") public boolean equals(Object other) { if (this == other) { return true; diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/RatisPipelineProvider.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/RatisPipelineProvider.java index ea7d3700966..6126d580c24 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/RatisPipelineProvider.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/RatisPipelineProvider.java @@ -38,6 +38,8 @@ import java.util.Set; import java.util.stream.Collectors; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + /** * Implements Api for creating ratis pipelines. */ @@ -48,6 +50,8 @@ public class RatisPipelineProvider implements PipelineProvider { private final Configuration conf; private static Scheduler scheduler; + //TODO static Scheduler should be removed!!!! HDDS-1128 + @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD") RatisPipelineProvider(NodeManager nodeManager, PipelineStateManager stateManager, Configuration conf) { this.nodeManager = nodeManager; diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java index 8baa03beaf5..e03293a8f14 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerRatisServer.java @@ -23,6 +23,7 @@ import java.io.File; import java.io.IOException; import java.net.InetSocketAddress; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -357,6 +358,6 @@ public static String getOMRatisDirectory(Configuration conf) { } private UUID getRaftGroupIdFromOmServiceId(String omServiceId) { - return UUID.nameUUIDFromBytes(omServiceId.getBytes()); + return UUID.nameUUIDFromBytes(omServiceId.getBytes(StandardCharsets.UTF_8)); } }