adoroszlai commented on code in PR #10007:
URL: https://github.com/apache/ozone/pull/10007#discussion_r3031971164
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/handlers/BucketHandler.java:
##########
@@ -100,15 +100,18 @@ public abstract OmDirectoryInfo getDirInfo(String[] names)
* @return subpath
*/
public static String buildSubpath(String path, String nextLevel) {
- String subpath = path;
- if (!subpath.startsWith(OM_KEY_PREFIX)) {
- subpath = OM_KEY_PREFIX + subpath;
- }
- subpath = removeTrailingSlashIfNeeded(subpath);
+ path = !path.startsWith(OM_KEY_PREFIX)
+ ? OM_KEY_PREFIX + path
+ : path;
+
+ StringBuilder sb = new StringBuilder(path)
+ .append(removeTrailingSlashIfNeeded(path));
Review Comment:
- This duplicates `path`.
- `StringBuilder` is unnecessary if `nextLevel == null`, and we can use
concatenation in the other case
- Better avoid reassigning parameter `path`.
So logic can be simplified:
```java
String subpath = !subpath.startsWith(OM_KEY_PREFIX)
? OM_KEY_PREFIX + path
: path;
subpath = removeTrailingSlashIfNeeded(subpath);
return nextLevel != null
? subpath + OM_KEY_PREFIX + nextLevel
: subpath;
```
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/nssummary/DiskUsageSubCommand.java:
##########
@@ -162,13 +162,14 @@ public Void call() throws Exception {
if (cnt >= limit) {
break;
}
- String subPath = subPathDU.path("path").asText("");
+ StringBuilder sb = new
StringBuilder(subPathDU.path("path").asText(""));
// differentiate key from other types
if (!subPathDU.path("isKey").asBoolean(false)) {
- subPath += OM_KEY_PREFIX;
+ sb.append(OM_KEY_PREFIX);
}
Review Comment:
I think PMD is really wrong here: previously the (internal) `StringBuilder`
was created only conditionally, but now it is eagerly created. We can avoid
that.
```java
String pathValue = subPathDU.path("path").asText("");
boolean isDir = !subPathDU.path("isKey").asBoolean(false);
String subPath = isDir ? (pathValue + OM_KEY_PREFIX) : pathValue;
```
--
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]