@@ -1013,6 +1012,7 @@ public class ColumnFamilyOptions extends RocksObject * * @return true iff blob files are currently enabled */ + @Override public boolean enableBlobFiles() { return enableBlobFiles(nativeHandle_); } diff --git a/java/src/main/java/org/rocksdb/CompactionStyle.java b/java/src/main/java/org/rocksdb/CompactionStyle.java index 794074df65..7b955a7a24 100644 --- a/java/src/main/java/org/rocksdb/CompactionStyle.java +++ b/java/src/main/java/org/rocksdb/CompactionStyle.java @@ -5,8 +5,6 @@ package org.rocksdb; -import java.util.List; - /** * Enum CompactionStyle *
@@ -25,7 +23,7 @@ import java.util.List; * the old data, so it's basically a TTL compaction style. *
diff --git a/java/src/main/java/org/rocksdb/EncodingType.java b/java/src/main/java/org/rocksdb/EncodingType.java index c2790c1954..e93ffcc23c 100644 --- a/java/src/main/java/org/rocksdb/EncodingType.java +++ b/java/src/main/java/org/rocksdb/EncodingType.java @@ -47,7 +47,7 @@ public enum EncodingType { return value_; } - private EncodingType(final byte value) { + EncodingType(final byte value) { value_ = value; } diff --git a/java/src/main/java/org/rocksdb/Env.java b/java/src/main/java/org/rocksdb/Env.java index 9499cf3b6a..6783d81581 100644 --- a/java/src/main/java/org/rocksdb/Env.java +++ b/java/src/main/java/org/rocksdb/Env.java @@ -26,8 +26,9 @@ public abstract class Env extends RocksObject { * * @return the default {@link org.rocksdb.RocksEnv} instance. */ + @SuppressWarnings({"PMD.CloseResource", "PMD.AssignmentInOperand"}) public static Env getDefault() { - RocksEnv defaultEnv = null; + RocksEnv defaultEnv; RocksEnv newDefaultEnv = null; while ((defaultEnv = SINGULAR_DEFAULT_ENV.get()) == null) { diff --git a/java/src/main/java/org/rocksdb/EventListener.java b/java/src/main/java/org/rocksdb/EventListener.java index 27652eaf89..a263258063 100644 --- a/java/src/main/java/org/rocksdb/EventListener.java +++ b/java/src/main/java/org/rocksdb/EventListener.java @@ -5,8 +5,6 @@ package org.rocksdb; -import java.util.List; - /** * EventListener class contains a set of callback functions that will * be called when specific RocksDB event happens such as flush. It can @@ -16,14 +14,14 @@ import java.util.List; * Note that callback functions should not run for an extended period of * time before the function returns, otherwise RocksDB may be blocked. * For example, it is not suggested to do - * {@link RocksDB#compactFiles(CompactionOptions, ColumnFamilyHandle, List, int, int, + * {@link RocksDB#compactFiles(CompactionOptions, ColumnFamilyHandle, java.util.List, int, int, * CompactionJobInfo)} (as it may run for a long while) or issue many of * {@link RocksDB#put(ColumnFamilyHandle, WriteOptions, byte[], byte[])} * (as Put may be blocked in certain cases) in the same thread in the * EventListener callback. *
* However, doing - * {@link RocksDB#compactFiles(CompactionOptions, ColumnFamilyHandle, List, int, int, + * {@link RocksDB#compactFiles(CompactionOptions, ColumnFamilyHandle, java.util.List, int, int, * CompactionJobInfo)} and {@link RocksDB#put(ColumnFamilyHandle, WriteOptions, byte[], byte[])} in * another thread is considered safe. *
diff --git a/java/src/main/java/org/rocksdb/HashLinkedListMemTableConfig.java b/java/src/main/java/org/rocksdb/HashLinkedListMemTableConfig.java
index 4bc860d1ca..a9868df57d 100644
--- a/java/src/main/java/org/rocksdb/HashLinkedListMemTableConfig.java
+++ b/java/src/main/java/org/rocksdb/HashLinkedListMemTableConfig.java
@@ -15,7 +15,7 @@ package org.rocksdb;
* and post a warning in the LOG.
*/
public class HashLinkedListMemTableConfig extends MemTableConfig {
- public static final long DEFAULT_BUCKET_COUNT = 50000;
+ public static final long DEFAULT_BUCKET_COUNT = 50_000;
public static final long DEFAULT_HUGE_PAGE_TLB_SIZE = 0;
public static final int DEFAULT_BUCKET_ENTRIES_LOG_THRES = 4096;
public static final boolean
diff --git a/java/src/main/java/org/rocksdb/HashSkipListMemTableConfig.java b/java/src/main/java/org/rocksdb/HashSkipListMemTableConfig.java
index 7cfa1c0dfe..80d6b71151 100644
--- a/java/src/main/java/org/rocksdb/HashSkipListMemTableConfig.java
+++ b/java/src/main/java/org/rocksdb/HashSkipListMemTableConfig.java
@@ -15,7 +15,7 @@ package org.rocksdb;
* and post a warning in the LOG.
*/
public class HashSkipListMemTableConfig extends MemTableConfig {
- public static final int DEFAULT_BUCKET_COUNT = 1000000;
+ public static final int DEFAULT_BUCKET_COUNT = 1_000_000;
public static final int DEFAULT_BRANCHING_FACTOR = 4;
public static final int DEFAULT_HEIGHT = 4;
diff --git a/java/src/main/java/org/rocksdb/LevelMetaData.java b/java/src/main/java/org/rocksdb/LevelMetaData.java
index c5685098be..424bcb0266 100644
--- a/java/src/main/java/org/rocksdb/LevelMetaData.java
+++ b/java/src/main/java/org/rocksdb/LevelMetaData.java
@@ -11,6 +11,7 @@ import java.util.List;
/**
* The metadata that describes a level.
*/
+@SuppressWarnings("PMD.MissingStaticMethodInNonInstantiatableClass")
public class LevelMetaData {
private final int level;
private final long size;
diff --git a/java/src/main/java/org/rocksdb/LiveFileMetaData.java b/java/src/main/java/org/rocksdb/LiveFileMetaData.java
index 35d883e180..4c670e3ae0 100644
--- a/java/src/main/java/org/rocksdb/LiveFileMetaData.java
+++ b/java/src/main/java/org/rocksdb/LiveFileMetaData.java
@@ -8,6 +8,7 @@ package org.rocksdb;
/**
* The full set of metadata associated with each SST file.
*/
+@SuppressWarnings("PMD.MissingStaticMethodInNonInstantiatableClass")
public class LiveFileMetaData extends SstFileMetaData {
private final byte[] columnFamilyName;
private final int level;
@@ -40,6 +41,7 @@ public class LiveFileMetaData extends SstFileMetaData {
*
* @return the name of the column family
*/
+ @SuppressWarnings("PMD.MethodReturnsInternalArray")
public byte[] columnFamilyName() {
return columnFamilyName;
}
diff --git a/java/src/main/java/org/rocksdb/LogFile.java b/java/src/main/java/org/rocksdb/LogFile.java
index ef24a6427c..5ee2c9fcc6 100644
--- a/java/src/main/java/org/rocksdb/LogFile.java
+++ b/java/src/main/java/org/rocksdb/LogFile.java
@@ -5,6 +5,7 @@
package org.rocksdb;
+@SuppressWarnings("PMD.MissingStaticMethodInNonInstantiatableClass")
public class LogFile {
private final String pathName;
private final long logNumber;
diff --git a/java/src/main/java/org/rocksdb/MemoryUtil.java b/java/src/main/java/org/rocksdb/MemoryUtil.java
index 15b9f001a4..dac6d9b84e 100644
--- a/java/src/main/java/org/rocksdb/MemoryUtil.java
+++ b/java/src/main/java/org/rocksdb/MemoryUtil.java
@@ -27,7 +27,9 @@ public class MemoryUtil {
* @param caches Set of caches to collect memory usage for.
* @return Map from {@link MemoryUsageType} to memory usage as a {@link Long}.
*/
- public static Map
* See also {@link #close()}.
*/
+ @SuppressWarnings("PMD.EmptyCatchBlock")
@Override
public void close() {
if (owningHandle_.compareAndSet(true, false)) {
diff --git a/java/src/main/java/org/rocksdb/OptionString.java b/java/src/main/java/org/rocksdb/OptionString.java
index 61d2a94fef..bcbf1d1529 100644
--- a/java/src/main/java/org/rocksdb/OptionString.java
+++ b/java/src/main/java/org/rocksdb/OptionString.java
@@ -9,6 +9,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
+@SuppressWarnings("PMD.AvoidStringBufferField")
public class OptionString {
private static final char kvPairSeparator = ';';
private static final char kvSeparator = '=';
@@ -39,6 +40,7 @@ public class OptionString {
return new Value(null, complex);
}
+ @Override
public String toString() {
final StringBuilder sb = new StringBuilder();
if (isList()) {
@@ -68,6 +70,7 @@ public class OptionString {
this.value = value;
}
+ @Override
public String toString() {
return "" + key + "=" + value;
}
@@ -75,6 +78,8 @@ public class OptionString {
static class Parser {
static class Exception extends RuntimeException {
+ private static final long serialVersionUID = 752283782841276408L;
+
public Exception(final String s) {
super(s);
}
@@ -122,7 +127,7 @@ public class OptionString {
return (sb.length() > 0);
}
- private boolean is(final char c) {
+ private boolean isChar(final char c) {
return (sb.length() > 0 && sb.charAt(0) == c);
}
@@ -151,10 +156,10 @@ public class OptionString {
}
private String parseSimpleValue() {
- if (is(wrappedValueBegin)) {
+ if (isChar(wrappedValueBegin)) {
next();
final String result = parseSimpleValue();
- if (!is(wrappedValueEnd)) {
+ if (!isChar(wrappedValueEnd)) {
exception("Expected to end a wrapped value with " + wrappedValueEnd);
}
next();
@@ -172,7 +177,7 @@ public class OptionString {
final List
* See also {@link #close()}.
*/
+ @SuppressWarnings("PMD.EmptyCatchBlock")
@Override
public void close() {
- for (final ColumnFamilyHandle columnFamilyHandle : ownedColumnFamilyHandles) {
+ for (final ColumnFamilyHandle columnFamilyHandle : // NOPMD - CloseResource
+ ownedColumnFamilyHandles) {
columnFamilyHandle.close();
}
ownedColumnFamilyHandles.clear();
@@ -706,7 +726,7 @@ public class RocksDB extends RocksObject {
final List
* See also {@link #close()}.
*/
+ @SuppressWarnings("PMD.EmptyCatchBlock")
@Override
public void close() {
if (owningHandle_.compareAndSet(true, false)) {
@@ -218,7 +220,7 @@ public class TransactionDB extends RocksDB
final List
* See also {@link #close()}.
*/
+ @SuppressWarnings("PMD.EmptyCatchBlock")
@Override
public void close() {
if (owningHandle_.compareAndSet(true, false)) {
diff --git a/java/src/main/java/org/rocksdb/WBWIRocksIterator.java b/java/src/main/java/org/rocksdb/WBWIRocksIterator.java
index e0b99b1b51..25d6e6f9d6 100644
--- a/java/src/main/java/org/rocksdb/WBWIRocksIterator.java
+++ b/java/src/main/java/org/rocksdb/WBWIRocksIterator.java
@@ -159,10 +159,10 @@ public class WBWIRocksIterator
* no value
*/
public DirectSlice getValue() {
- if(!value.isOwningHandle()) {
- return null; //TODO(AR) migrate to JDK8 java.util.Optional#empty()
- } else {
+ if (value.isOwningHandle()) {
return value;
+ } else {
+ return null; // TODO(AR) migrate to JDK8 java.util.Optional#empty()
}
}
@@ -178,6 +178,7 @@ public class WBWIRocksIterator
return (key == null) ? 0 : key.hashCode();
}
+ @SuppressWarnings("PMD.CloseResource")
@Override
public boolean equals(final Object other) {
if(other == null) {
diff --git a/java/src/main/java/org/rocksdb/WriteBufferManager.java b/java/src/main/java/org/rocksdb/WriteBufferManager.java
index 9c56458802..40176aba42 100644
--- a/java/src/main/java/org/rocksdb/WriteBufferManager.java
+++ b/java/src/main/java/org/rocksdb/WriteBufferManager.java
@@ -9,7 +9,6 @@ package org.rocksdb;
* Java wrapper over native write_buffer_manager class
*/
public class WriteBufferManager extends RocksObject {
-
/**
* Construct a new instance of WriteBufferManager.
*
diff --git a/java/src/main/java/org/rocksdb/util/BytewiseComparator.java b/java/src/main/java/org/rocksdb/util/BytewiseComparator.java
index 9561b0a317..202241d3ba 100644
--- a/java/src/main/java/org/rocksdb/util/BytewiseComparator.java
+++ b/java/src/main/java/org/rocksdb/util/BytewiseComparator.java
@@ -52,9 +52,9 @@ public final class BytewiseComparator extends AbstractComparator {
return r;
}
+ @SuppressWarnings("PMD.EmptyControlStatement")
@Override
- public void findShortestSeparator(final ByteBuffer start,
- final ByteBuffer limit) {
+ public void findShortestSeparator(final ByteBuffer start, final ByteBuffer limit) {
// Find length of common prefix
final int minLength = Math.min(start.remaining(), limit.remaining());
int diffIndex = 0;
diff --git a/java/src/main/java/org/rocksdb/util/Environment.java b/java/src/main/java/org/rocksdb/util/Environment.java
index 9ad51c7c73..53ff65d263 100644
--- a/java/src/main/java/org/rocksdb/util/Environment.java
+++ b/java/src/main/java/org/rocksdb/util/Environment.java
@@ -3,12 +3,20 @@ package org.rocksdb.util;
import java.io.File;
import java.io.IOException;
+import java.util.Locale;
public class Environment {
- private static String OS = System.getProperty("os.name").toLowerCase();
- private static String ARCH = System.getProperty("os.arch").toLowerCase();
+ @SuppressWarnings("FieldMayBeFinal")
+ private static String OS = System.getProperty("os.name").toLowerCase(Locale.getDefault());
+ @SuppressWarnings("FieldMayBeFinal")
+ private static String ARCH = System.getProperty("os.arch").toLowerCase(Locale.getDefault());
+ @SuppressWarnings("FieldMayBeFinal")
private static String MUSL_ENVIRONMENT = System.getenv("ROCKSDB_MUSL_LIBC");
+ private static final String LIBC_MUSL_PREFIX = "libc.musl";
+
+ private static final String SPARCV9 = "sparcv9";
+
/**
* Will be lazily initialised by {@link #isMuslLibc()} instead of the previous static
* initialisation. The lazy initialisation prevents Windows from reporting suspicious behaviour of
@@ -70,6 +78,7 @@ public class Environment {
*
* @return true if the environment has a musl libc, false otherwise.
*/
+ @SuppressWarnings("PMD.EmptyCatchBlock")
static boolean initIsMuslLibc() {
// consider explicit user setting from environment first
if ("true".equalsIgnoreCase(MUSL_ENVIRONMENT)) {
@@ -114,7 +123,7 @@ public class Environment {
return false;
}
for (final File f : libFiles) {
- if (f.getName().startsWith("libc.musl")) {
+ if (f.getName().startsWith(LIBC_MUSL_PREFIX)) {
return true;
}
}
@@ -132,7 +141,7 @@ public class Environment {
}
public static boolean is64Bit() {
- if (ARCH.indexOf("sparcv9") >= 0) {
+ if (ARCH.contains(SPARCV9)) {
return true;
}
return (ARCH.indexOf("64") > 0);
diff --git a/java/src/main/java/org/rocksdb/util/IntComparator.java b/java/src/main/java/org/rocksdb/util/IntComparator.java
index cc096cd149..2caf0c6015 100644
--- a/java/src/main/java/org/rocksdb/util/IntComparator.java
+++ b/java/src/main/java/org/rocksdb/util/IntComparator.java
@@ -48,7 +48,7 @@ public final class IntComparator extends AbstractComparator {
*
* @return negative if a < b, 0 if a == b, positive otherwise
*/
- private final int compareIntKeys(final ByteBuffer a, final ByteBuffer b) {
+ private int compareIntKeys(final ByteBuffer a, final ByteBuffer b) {
final int iA = a.getInt();
final int iB = b.getInt();
diff --git a/java/src/main/java/org/rocksdb/util/ReverseBytewiseComparator.java b/java/src/main/java/org/rocksdb/util/ReverseBytewiseComparator.java
index 4c06f80aac..3d3c429416 100644
--- a/java/src/main/java/org/rocksdb/util/ReverseBytewiseComparator.java
+++ b/java/src/main/java/org/rocksdb/util/ReverseBytewiseComparator.java
@@ -38,9 +38,9 @@ public final class ReverseBytewiseComparator extends AbstractComparator {
return -BytewiseComparator._compare(a, b);
}
+ @SuppressWarnings("PMD.EmptyControlStatement")
@Override
- public void findShortestSeparator(final ByteBuffer start,
- final ByteBuffer limit) {
+ public void findShortestSeparator(final ByteBuffer start, final ByteBuffer limit) {
// Find length of common prefix
final int minLength = Math.min(start.remaining(), limit.remaining());
int diffIndex = 0;
diff --git a/java/src/test/java/org/rocksdb/DBOptionsTest.java b/java/src/test/java/org/rocksdb/DBOptionsTest.java
index d79f78db78..cb7eabcfb1 100644
--- a/java/src/test/java/org/rocksdb/DBOptionsTest.java
+++ b/java/src/test/java/org/rocksdb/DBOptionsTest.java
@@ -886,6 +886,8 @@ public class DBOptionsTest {
wasCalled2.set(true);
}
}) {
+ assertThat(options.setListeners(null)).isEqualTo(options);
+ assertThat(options.listeners().size()).isEqualTo(0);
assertThat(options.setListeners(Arrays.asList(el1, el2))).isEqualTo(options);
final List