From 6f3538bb4bea4571acdc026f438213ca2fd372b1 Mon Sep 17 00:00:00 2001 From: Andrew Purtell Date: Tue, 26 Jul 2022 18:04:14 -0700 Subject: [PATCH] HBASE-27236 Clean up error-prone warnings in hbase-hbtop (#4649) Signed-off-by: Duo Zhang --- .../src/main/java/org/apache/hadoop/hbase/hbtop/HBTop.java | 6 ++++-- .../main/java/org/apache/hadoop/hbase/hbtop/mode/Mode.java | 1 + .../apache/hadoop/hbase/hbtop/mode/RegionModeStrategy.java | 1 + .../apache/hadoop/hbase/hbtop/terminal/TerminalPrinter.java | 1 + .../hadoop/hbase/hbtop/terminal/impl/KeyPressGenerator.java | 5 ++++- .../hadoop/hbase/hbtop/terminal/impl/TerminalImpl.java | 4 +++- .../test/java/org/apache/hadoop/hbase/hbtop/TestUtils.java | 1 + 7 files changed, 15 insertions(+), 4 deletions(-) diff --git a/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/HBTop.java b/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/HBTop.java index 7e6944f73e7..84c4dc6e715 100644 --- a/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/HBTop.java +++ b/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/HBTop.java @@ -36,6 +36,7 @@ import org.apache.yetus.audience.InterfaceAudience; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.hbase.thirdparty.com.google.common.base.Splitter; import org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine; import org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser; import org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter; @@ -119,6 +120,7 @@ public class HBTop extends Configured implements Tool { try { delay = Integer.parseInt(commandLine.getOptionValue("delay")); } catch (NumberFormatException ignored) { + // Deliberately ignored, we handle the issue below. } if (delay < 1) { @@ -163,7 +165,7 @@ public class HBTop extends Configured implements Tool { } if (commandLine.hasOption("fields")) { - String[] fields = commandLine.getOptionValue("fields").split(","); + Iterable fields = Splitter.on(',').split(commandLine.getOptionValue("fields")); initialFields = new ArrayList<>(); for (String field : fields) { Optional fieldInfo = initialMode.getFieldInfos().stream() @@ -177,7 +179,7 @@ public class HBTop extends Configured implements Tool { } if (commandLine.hasOption("filters")) { - String[] filters = commandLine.getOptionValue("filters").split(","); + Iterable filters = Splitter.on(',').split(commandLine.getOptionValue("filters")); List fields = initialMode.getFieldInfos().stream().map(FieldInfo::getField) .collect(Collectors.toList()); for (String filter : filters) { diff --git a/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/mode/Mode.java b/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/mode/Mode.java index 4ae1b4faf33..fd8a50e85e7 100644 --- a/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/mode/Mode.java +++ b/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/mode/Mode.java @@ -31,6 +31,7 @@ import org.apache.yetus.audience.InterfaceAudience; * Represents a display mode in the top screen. */ @InterfaceAudience.Private +@SuppressWarnings("ImmutableEnumChecker") public enum Mode { NAMESPACE("Namespace", "Record per Namespace", new NamespaceModeStrategy()), TABLE("Table", "Record per Table", new TableModeStrategy()), diff --git a/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/mode/RegionModeStrategy.java b/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/mode/RegionModeStrategy.java index 9a70f61005a..5932ffb2279 100644 --- a/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/mode/RegionModeStrategy.java +++ b/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/mode/RegionModeStrategy.java @@ -115,6 +115,7 @@ public final class RegionModeStrategy implements ModeStrategy { elements.length == 4 ? Integer.valueOf(Bytes.toString(elements[3])).toString() : ""; region = RegionInfo.encodeRegionName(regionMetrics.getRegionName()); } catch (IOException ignored) { + // Exception deliberately ignored } builder.put(Field.NAMESPACE, namespaceName); diff --git a/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/terminal/TerminalPrinter.java b/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/terminal/TerminalPrinter.java index 52818e42a7d..1f955b2e224 100644 --- a/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/terminal/TerminalPrinter.java +++ b/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/terminal/TerminalPrinter.java @@ -61,6 +61,7 @@ public interface TerminalPrinter { return this; } + @SuppressWarnings("AnnotateFormatMethod") default TerminalPrinter printFormat(String format, Object... args) { print(String.format(format, args)); return this; diff --git a/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/terminal/impl/KeyPressGenerator.java b/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/terminal/impl/KeyPressGenerator.java index 15cbb3070c3..8b8a5dc9f51 100644 --- a/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/terminal/impl/KeyPressGenerator.java +++ b/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/terminal/impl/KeyPressGenerator.java @@ -112,7 +112,10 @@ public class KeyPressGenerator { } else { Thread.sleep(20); } - } catch (InterruptedException ignored) { + } catch (InterruptedException e) { + // Restore interrupt status + Thread.currentThread().interrupt(); + done = true; } catch (IOException e) { LOGGER.error("Caught an exception", e); done = true; diff --git a/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/terminal/impl/TerminalImpl.java b/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/terminal/impl/TerminalImpl.java index e579b0ff057..0d6654ddbca 100644 --- a/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/terminal/impl/TerminalImpl.java +++ b/hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/terminal/impl/TerminalImpl.java @@ -213,7 +213,9 @@ public class TerminalImpl implements Terminal { try { process.waitFor(); - } catch (InterruptedException ignored) { + } catch (InterruptedException e) { + // Restore interrupt status + Thread.currentThread().interrupt(); } int exitValue = process.exitValue(); diff --git a/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/TestUtils.java b/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/TestUtils.java index 0f6a02a27c1..0968a1d5723 100644 --- a/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/TestUtils.java +++ b/hbase-hbtop/src/test/java/org/apache/hadoop/hbase/hbtop/TestUtils.java @@ -114,6 +114,7 @@ public final class TestUtils { .build(); } + @SuppressWarnings("JavaUtilDate") private static RegionMetrics createRegionMetrics(String regionName, long readRequestCount, long filteredReadRequestCount, long writeRequestCount, Size storeFileSize, Size uncompressedStoreFileSize, int storeFileCount, Size memStoreSize, float locality,