Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dev-support/pmd/pmd-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<rule ref="category/java/performance.xml/InefficientEmptyStringCheck"/>
<rule ref="category/java/performance.xml/InefficientStringBuffering"/>
<rule ref="category/java/performance.xml/StringInstantiation"/>
<rule ref="category/java/performance.xml/StringToString"/>
<rule ref="category/java/performance.xml/UseArraysAsList"/>
<rule ref="category/java/performance.xml/UseIndexOfChar"/>
Comment on lines +45 to +47
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please keep alphabetical order, which makes it easier to spot enabled rules at a glance

<rule ref="category/java/performance.xml/UseStringBufferLength"/>

<rule ref="category/java/codestyle.xml/FieldDeclarationsShouldBeAtStartOfClass">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.SplittableRandom;
Expand Down Expand Up @@ -363,13 +364,8 @@ private ByteBuffer[] allocateBuffers(int num, int size) {
}

private void addDataStreamsToFactory(ByteBuffer[] data, ByteBuffer[] parity) {
List<ByteBuffer> dataStreams = new ArrayList<>();
for (ByteBuffer b : data) {
dataStreams.add(b);
}
for (ByteBuffer b : parity) {
dataStreams.add(b);
}
List<ByteBuffer> dataStreams = new ArrayList<>(Arrays.asList(data));
dataStreams.addAll(Arrays.asList(parity));
streamFactory.setBlockStreamData(dataStreams);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -817,13 +817,8 @@ private ECBlockReconstructedStripeInputStream createInputStream(
}

private void addDataStreamsToFactory(ByteBuffer[] data, ByteBuffer[] parity) {
List<ByteBuffer> dataStreams = new ArrayList<>();
for (ByteBuffer b : data) {
dataStreams.add(b);
}
for (ByteBuffer b : parity) {
dataStreams.add(b);
}
List<ByteBuffer> dataStreams = new ArrayList<>(Arrays.asList(data));
dataStreams.addAll(Arrays.asList(parity));
streamFactory.setBlockStreamData(dataStreams);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,7 @@ public Object construct(Node node) {
private class ConstructLong extends AbstractConstruct {
@Override
public Object construct(Node node) {
String value = constructScalar((ScalarNode) node).toString()
.replaceAll("_", "");
String value = constructScalar((ScalarNode) node).replaceAll("_", "");
int sign = +1;
char first = value.charAt(0);
if (first == '-') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ private Integer getPid() {
if (StringUtils.isBlank(pidStr)) {
String name = ManagementFactory.getRuntimeMXBean().getName();
if (name != null) {
int idx = name.indexOf("@");
int idx = name.indexOf('@');
if (idx != -1) {
pidStr = name.substring(0, name.indexOf("@"));
pidStr = name.substring(0, idx);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private void writeAttribute(JsonGenerator jg, ObjectName oname, MBeanAttributeIn
if (attr.isReadable()) {
String attName = attr.getName();
if (!"modelerType".equals(attName)) {
if (attName.indexOf("=") < 0 && attName.indexOf(":") < 0 && attName.indexOf(" ") < 0) {
if (attName.indexOf('=') < 0 && attName.indexOf(':') < 0 && attName.indexOf(' ') < 0) {
Object value = null;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static String parseInputPath(String path) {
if (!path.startsWith("ofs://")) {
return path;
}
int idx = path.indexOf("/", OFS_PREFIX.length());
int idx = path.indexOf('/', OFS_PREFIX.length());
if (idx == -1) {
return path.substring(OFS_PREFIX.length());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void testDataNodeByUuidOutput()
Matcher m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());

p = Pattern.compile(nodes.get(0).getNodeID().getUuid().toString(),
p = Pattern.compile(nodes.get(0).getNodeID().getUuid(),
Pattern.MULTILINE);
m = p.matcher(outContent.toString(DEFAULT_ENCODING));
assertTrue(m.find());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ private void deleteFSOKey(OzoneBucket bucket, String keyName)
Path userTrash = new Path(trashRoot, username);
Path userTrashCurrent = new Path(userTrash, CURRENT);

String trashDirectory = (keyName.contains("/")
? new Path(userTrashCurrent, keyName.substring(0,
keyName.lastIndexOf("/")))
int lastDelimiterIndex = keyName.lastIndexOf('/');
String trashDirectory = (lastDelimiterIndex >= 0
? new Path(userTrashCurrent, keyName.substring(0, lastDelimiterIndex))
: userTrashCurrent).toUri().getPath();

String toKeyName = new Path(userTrashCurrent, keyName).toUri().getPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ public static OzoneAcl parseAcl(String acl)

// Check if acl string contains scope info.
if (parts[2].matches(ACL_SCOPE_REGEX)) {
int indexOfOpenBracket = parts[2].indexOf("[");
int indexOfOpenBracket = parts[2].indexOf('[');
bits = parts[2].substring(0, indexOfOpenBracket);
aclScope = AclScope.valueOf(parts[2].substring(indexOfOpenBracket + 1,
parts[2].indexOf("]")));
parts[2].indexOf(']')));
}

EnumSet<ACLType> acls = EnumSet.noneOf(ACLType.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private Exception unwrapException(Exception ex) {
// exception potentially generated by OzoneManagerServiceGrpc
Class<?> realClass = Class.forName(status.getDescription()
.substring(0, status.getDescription()
.indexOf(":")));
.indexOf(':')));
Class<? extends Exception> cls = realClass
.asSubclass(Exception.class);
Constructor<? extends Exception> cn = cls.getConstructor(String.class);
Expand All @@ -231,9 +231,10 @@ private Exception unwrapException(Exception ex) {
IOException remote = null;
try {
String cause = status.getDescription();
cause = cause.substring(cause.indexOf(":") + 2);
remote = new RemoteException(cause.substring(0, cause.indexOf(":")),
cause.substring(cause.indexOf(":") + 1));
int colonIndex = cause.indexOf(':');
cause = cause.substring(colonIndex + 2);
remote = new RemoteException(cause.substring(0, colonIndex),
cause.substring(colonIndex + 1));
grpcException.initCause(remote);
} catch (Exception e) {
LOG.error("cannot get cause for remote exception");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ void testListStatusRootAndVolumeNonRecursive() throws Exception {
* Helper function to do FileSystem#listStatus recursively.
* Simulate what FsShell does, using DFS.
*/
@SuppressWarnings("PMD.UseArraysAsList")
private void listStatusRecursiveHelper(Path curPath, List<FileStatus> result)
throws IOException {
FileStatus[] startList = fs.listStatus(curPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ public static Map<String, List<String>> readFileToMap(String filePath) throws IO
if (!trimmedLine.contains("\t")) {
continue;
}
int tabIndex = trimmedLine.indexOf("\t");
int tabIndex = trimmedLine.indexOf('\t');
if (tabIndex > 0) {
// value is the full path that needs to be constructed
String value = trimmedLine.substring(0, tabIndex).trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ private void logVersionMismatch(OzoneConfiguration conf, ScmInfo scmInfo) {
String scmBlockAddress = scmBlockAddressBuilder.toString();
if (!StringUtils.isBlank(scmBlockAddress)) {
scmBlockAddress = scmBlockAddress.substring(0,
scmBlockAddress.lastIndexOf(","));
scmBlockAddress.lastIndexOf(','));
}
if (!scmInfo.getClusterId().equals(omStorage.getClusterID())) {
LOG.error("clusterId from {} is {}, but is {} in {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,7 @@ public boolean rename(Path src, Path dst) throws IOException {
}

if (srcStatus.isDirectory()) {
if (dstPath.toString()
.startsWith(srcPath.toString() + OZONE_URI_DELIMITER)) {
if (dstPath.startsWith(srcPath + OZONE_URI_DELIMITER)) {
LOG.trace("Cannot rename a directory to a subdirectory of self");
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ private String getDomainName(String host) {
}

private String checkHostWithoutPort(String host) {
if (host.contains(":")) {
return host.substring(0, host.lastIndexOf(":"));
int portIndex = host.lastIndexOf(':');
if (portIndex >= 0) {
return host.substring(0, portIndex);
} else {
return host;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void setup() {
conf = new OzoneConfiguration();
s3HttpAddr = "localhost:9878";
conf.set(S3GatewayConfigKeys.OZONE_S3G_HTTP_ADDRESS_KEY, s3HttpAddr);
s3HttpAddr = s3HttpAddr.substring(0, s3HttpAddr.lastIndexOf(":"));
s3HttpAddr = s3HttpAddr.substring(0, s3HttpAddr.lastIndexOf(':'));
conf.set(S3GatewayConfigKeys.OZONE_S3G_DOMAIN_NAME, s3HttpAddr);
}

Expand Down