HDDS-1129. Fix findbug/checkstyle errors hdds projects. Contributed by Elek, Marton.

This commit is contained in:
Márton Elek 2019-02-18 18:39:57 +01:00
parent eedcc8e26e
commit 7c802c42dc
No known key found for this signature in database
GPG Key ID: D51EA8F00EE79B28
6 changed files with 32 additions and 10 deletions

View File

@ -109,7 +109,8 @@ public class BlockInputStream extends InputStream implements Seekable {
int dataout = EOF; int dataout = EOF;
if (available == 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 { } else {
dataout = Byte.toUnsignedInt(buffers.get(bufferIndex).get()); dataout = Byte.toUnsignedInt(buffers.get(bufferIndex).get());
} }
@ -149,7 +150,8 @@ public class BlockInputStream extends InputStream implements Seekable {
while (len > 0) { while (len > 0) {
int available = prepareRead(len); int available = prepareRead(len);
if (available == EOF) { 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; return total != 0 ? total : EOF;
} }
buffers.get(bufferIndex).get(b, off + total, available); buffers.get(bufferIndex).get(b, off + total, available);
@ -167,7 +169,7 @@ public class BlockInputStream extends InputStream implements Seekable {
} }
/** /**
* 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 * @return true if EOF, false if more data is available
*/ */
@ -177,7 +179,8 @@ public class BlockInputStream extends InputStream implements Seekable {
} else { } else {
// if there are any chunks, we better be at the last chunk for EOF // if there are any chunks, we better be at the last chunk for EOF
Preconditions.checkState(((chunks == null) || chunks.isEmpty() || Preconditions.checkState(((chunks == null) || chunks.isEmpty() ||
chunkIndex == (chunks.size() - 1)), "EOF detected, but not at the last chunk"); chunkIndex == (chunks.size() - 1)),
"EOF detected, but not at the last chunk");
return true; return true;
} }
} }

View File

@ -189,6 +189,13 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
<version>${junit.jupiter.version}</version> <version>${junit.jupiter.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>findbugs</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<dependencies> <dependencies>

View File

@ -100,6 +100,11 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>org.bouncycastle</groupId> <groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId> <artifactId>bcprov-jdk15on</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>findbugs</artifactId>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.hdds.scm.pipeline; package org.apache.hadoop.hdds.scm.pipeline;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor; import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType; import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType;
@ -328,13 +329,13 @@ class PipelineStateMap {
return updatedPipeline; return updatedPipeline;
} }
private class PipelineQuery { private static class PipelineQuery {
private ReplicationType type; private ReplicationType type;
private ReplicationFactor factor; private ReplicationFactor factor;
PipelineQuery(ReplicationType type, ReplicationFactor factor) { PipelineQuery(ReplicationType type, ReplicationFactor factor) {
this.type = type; this.type = Preconditions.checkNotNull(type);
this.factor = factor; this.factor = Preconditions.checkNotNull(factor);
} }
PipelineQuery(Pipeline pipeline) { PipelineQuery(Pipeline pipeline) {
@ -343,6 +344,7 @@ class PipelineStateMap {
} }
@Override @Override
@SuppressFBWarnings("NP_EQUALS_SHOULD_HANDLE_NULL_ARGUMENT")
public boolean equals(Object other) { public boolean equals(Object other) {
if (this == other) { if (this == other) {
return true; return true;

View File

@ -38,6 +38,8 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/** /**
* Implements Api for creating ratis pipelines. * Implements Api for creating ratis pipelines.
*/ */
@ -48,6 +50,8 @@ public class RatisPipelineProvider implements PipelineProvider {
private final Configuration conf; private final Configuration conf;
private static Scheduler scheduler; private static Scheduler scheduler;
//TODO static Scheduler should be removed!!!! HDDS-1128
@SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
RatisPipelineProvider(NodeManager nodeManager, RatisPipelineProvider(NodeManager nodeManager,
PipelineStateManager stateManager, Configuration conf) { PipelineStateManager stateManager, Configuration conf) {
this.nodeManager = nodeManager; this.nodeManager = nodeManager;

View File

@ -23,6 +23,7 @@ import com.google.common.base.Strings;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -357,6 +358,6 @@ public final class OzoneManagerRatisServer {
} }
private UUID getRaftGroupIdFromOmServiceId(String omServiceId) { private UUID getRaftGroupIdFromOmServiceId(String omServiceId) {
return UUID.nameUUIDFromBytes(omServiceId.getBytes()); return UUID.nameUUIDFromBytes(omServiceId.getBytes(StandardCharsets.UTF_8));
} }
} }