Skip to content

Commit

Permalink
HDDS-10581. NPE in SummarySubCommand and DiskUsageSubCommand (apache#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ArafatKhan2198 authored Mar 24, 2024
1 parent 48e547a commit e39166f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,18 @@ public Void call() throws Exception {

JsonNode duResponse = JsonUtils.readTree(response);

if (duResponse.get("status").asText().equals("PATH_NOT_FOUND")) {
if ("PATH_NOT_FOUND".equals(duResponse.path("status").asText(""))) {
printPathNotFound();
} else {
if (parent.isNotValidBucketOrOBSBucket(path)) {
printBucketReminder();
}

long totalSize = duResponse.get("size").asLong();
long totalSize = duResponse.path("size").asLong(-1);
if (!noHeader) {
printWithUnderline("Path", false);
printKVSeparator();
System.out.println(duResponse.get("path").asText());
System.out.println(duResponse.path("path").asText(""));

printWithUnderline("Total Size", false);
printKVSeparator();
Expand All @@ -121,11 +121,11 @@ public Void call() throws Exception {
if (withReplica) {
printWithUnderline("Total Disk Usage", false);
printKVSeparator();
long du = duResponse.get("sizeWithReplica").asLong();
long du = duResponse.path("sizeWithReplica").asLong(-1);
System.out.println(FileUtils.byteCountToDisplaySize(du));
}

long sizeDirectKey = duResponse.get("sizeDirectKey").asLong();
long sizeDirectKey = duResponse.path("sizeDirectKey").asLong(-1);
if (!listFiles && sizeDirectKey != -1) {
printWithUnderline("Size of Direct Keys", false);
printKVSeparator();
Expand All @@ -134,7 +134,7 @@ public Void call() throws Exception {
printNewLines(1);
}

if (duResponse.get("subPathCount").asInt() == 0) {
if (duResponse.path("subPathCount").asInt(-1) == 0) {
if (totalSize == 0) {
// the object is empty
System.out.println("The object is empty.\n" +
Expand All @@ -157,19 +157,19 @@ public Void call() throws Exception {
seekStr = "";
}

ArrayNode subPaths = (ArrayNode) duResponse.get("subPaths");
ArrayNode subPaths = (ArrayNode) duResponse.path("subPaths");
int cnt = 0;
for (JsonNode subPathDU : subPaths) {
if (cnt >= limit) {
break;
}
String subPath = subPathDU.get("path").asText();
String subPath = subPathDU.path("path").asText("");
// differentiate key from other types
if (!subPathDU.get("isKey").asBoolean()) {
if (!subPathDU.path("isKey").asBoolean(false)) {
subPath += OM_KEY_PREFIX;
}
long size = subPathDU.get("size").asLong();
long sizeWithReplica = subPathDU.get("sizeWithReplica").asLong();
long size = subPathDU.path("size").asLong(-1);
long sizeWithReplica = subPathDU.path("sizeWithReplica").asLong(-1);
if (subPath.startsWith(seekStr)) {
printDURow(subPath, size, sizeWithReplica);
++cnt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ public Void call() throws Exception {
printKVSeparator();
System.out.println(summaryResponse.get("type"));

int numVol = summaryResponse.get("numVolume").asInt();
int numBucket = summaryResponse.get("numBucket").asInt();
int numDir = summaryResponse.get("numDir").asInt();
int numKey = summaryResponse.get("numKey").asInt();
int numVol = summaryResponse.path("numVolume").asInt(-1);
int numBucket = summaryResponse.path("numBucket").asInt(-1);
int numDir = summaryResponse.path("numDir").asInt(-1);
int numKey = summaryResponse.path("numKey").asInt(-1);

if (numVol != -1) {
printWithUnderline("Volumes", false);
Expand Down

0 comments on commit e39166f

Please sign in to comment.