ctubbsii commented on code in PR #5574:
URL: https://github.com/apache/accumulo/pull/5574#discussion_r2110594726
##########
core/src/main/java/org/apache/accumulo/core/util/Halt.java:
##########
@@ -29,27 +31,43 @@ public class Halt {
private static final Logger log = LoggerFactory.getLogger(Halt.class);
public static void halt(final String msg) {
- // ACCUMULO-3651 Changed level to error and added FATAL to message for
slf4j compatibility
- halt(0, new Runnable() {
- @Override
- public void run() {
- log.error("FATAL {}", msg);
- }
- });
+ halt(0, msg, Optional.empty(), null);
Review Comment:
It's a little weird to me that we have any methods that call this. Do we
have cases where we want to fatally halt, but still return with a "0" exit
code? I would assume we'd always exit with non-zero if we're halting because of
a fatal issue.
##########
core/src/main/java/org/apache/accumulo/core/util/Halt.java:
##########
@@ -29,27 +31,43 @@ public class Halt {
private static final Logger log = LoggerFactory.getLogger(Halt.class);
public static void halt(final String msg) {
- // ACCUMULO-3651 Changed level to error and added FATAL to message for
slf4j compatibility
- halt(0, new Runnable() {
- @Override
- public void run() {
- log.error("FATAL {}", msg);
- }
- });
+ halt(0, msg, Optional.empty(), null);
}
- public static void halt(final String msg, int status) {
- halt(status, new Runnable() {
- @Override
- public void run() {
- log.error("FATAL {}", msg);
- }
- });
+ public static void halt(final String msg, final int status) {
+ halt(status, msg, Optional.empty(), null);
Review Comment:
It might be simpler to just inline some of these overloaded methods. It's
confusing to know when to call which one.
##########
core/src/main/java/org/apache/accumulo/core/util/Halt.java:
##########
@@ -29,27 +31,43 @@ public class Halt {
private static final Logger log = LoggerFactory.getLogger(Halt.class);
public static void halt(final String msg) {
- // ACCUMULO-3651 Changed level to error and added FATAL to message for
slf4j compatibility
- halt(0, new Runnable() {
- @Override
- public void run() {
- log.error("FATAL {}", msg);
- }
- });
+ halt(0, msg, Optional.empty(), null);
}
- public static void halt(final String msg, int status) {
- halt(status, new Runnable() {
- @Override
- public void run() {
- log.error("FATAL {}", msg);
- }
- });
+ public static void halt(final String msg, final int status) {
+ halt(status, msg, Optional.empty(), null);
}
- public static void halt(final int status, Runnable runnable) {
+ public static void halt(final int status, final String msg, final
Optional<Throwable> exception) {
+ halt(status, msg, exception, null);
+ }
+
+ public static void halt(final int status, final String msg, final Runnable
runnable) {
+ halt(status, msg, Optional.empty(), runnable);
+ }
+ public static void halt(final int status, final String msg, final
Optional<Throwable> exception,
+ final Runnable runnable) {
try {
+ final String errorMessage = "FATAL " + msg;
+
+ Throwable t = null;
+ if (exception.isPresent()) {
+ t = exception.orElseThrow();
+ }
+ // Printing to stderr and to the log in case the message does not make
+ // it to the log. This could happen if an asynchronous logging impl is
used
+ System.err.println(errorMessage);
+ if (t != null) {
Review Comment:
It seems odd to do a null check here, after the Optional was already
evaluated. I wonder if this can be made more succinct.
##########
core/src/main/java/org/apache/accumulo/core/util/Halt.java:
##########
@@ -29,27 +31,43 @@ public class Halt {
private static final Logger log = LoggerFactory.getLogger(Halt.class);
public static void halt(final String msg) {
- // ACCUMULO-3651 Changed level to error and added FATAL to message for
slf4j compatibility
- halt(0, new Runnable() {
- @Override
- public void run() {
- log.error("FATAL {}", msg);
- }
- });
+ halt(0, msg, Optional.empty(), null);
}
- public static void halt(final String msg, int status) {
- halt(status, new Runnable() {
- @Override
- public void run() {
- log.error("FATAL {}", msg);
- }
- });
+ public static void halt(final String msg, final int status) {
+ halt(status, msg, Optional.empty(), null);
}
- public static void halt(final int status, Runnable runnable) {
+ public static void halt(final int status, final String msg, final
Optional<Throwable> exception) {
+ halt(status, msg, exception, null);
+ }
+
+ public static void halt(final int status, final String msg, final Runnable
runnable) {
+ halt(status, msg, Optional.empty(), runnable);
+ }
+ public static void halt(final int status, final String msg, final
Optional<Throwable> exception,
+ final Runnable runnable) {
Review Comment:
We're mixing Optionals with nullables. Either both params should be nullable
non-Optionals or both should use non-null Optionals. We shouldn't mix them.
##########
core/src/main/java/org/apache/accumulo/core/util/Halt.java:
##########
@@ -29,27 +31,43 @@ public class Halt {
private static final Logger log = LoggerFactory.getLogger(Halt.class);
public static void halt(final String msg) {
- // ACCUMULO-3651 Changed level to error and added FATAL to message for
slf4j compatibility
- halt(0, new Runnable() {
- @Override
- public void run() {
- log.error("FATAL {}", msg);
- }
- });
+ halt(0, msg, Optional.empty(), null);
}
- public static void halt(final String msg, int status) {
- halt(status, new Runnable() {
- @Override
- public void run() {
- log.error("FATAL {}", msg);
- }
- });
+ public static void halt(final String msg, final int status) {
+ halt(status, msg, Optional.empty(), null);
}
- public static void halt(final int status, Runnable runnable) {
+ public static void halt(final int status, final String msg, final
Optional<Throwable> exception) {
+ halt(status, msg, exception, null);
+ }
+
+ public static void halt(final int status, final String msg, final Runnable
runnable) {
+ halt(status, msg, Optional.empty(), runnable);
+ }
+ public static void halt(final int status, final String msg, final
Optional<Throwable> exception,
+ final Runnable runnable) {
try {
+ final String errorMessage = "FATAL " + msg;
+
+ Throwable t = null;
+ if (exception.isPresent()) {
+ t = exception.orElseThrow();
+ }
Review Comment:
This is equivalent to:
```suggestion
Throwable t = exception.orElse(null);
```
--
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]