This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new d389fcd758b2 CAMEL-23615: camel-tui - Fix unsafe type casts and
unguarded parsing
d389fcd758b2 is described below
commit d389fcd758b21cd3c85a43d0a24e975dd70055f2
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed May 27 10:09:34 2026 +0200
CAMEL-23615: camel-tui - Fix unsafe type casts and unguarded parsing
Fix unsafe `(Boolean)` casts from JSON that could cause
ClassCastException or NullPointerException — use
`Boolean.TRUE.equals()` instead. Guard `Long.parseLong()` on
tab switch to history with try-catch for NumberFormatException.
Closes #23547
---
.../dsl/jbang/core/commands/tui/CamelMonitor.java | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitor.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitor.java
index a6d30a66f615..4995629b631a 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitor.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitor.java
@@ -718,8 +718,13 @@ public class CamelMonitor extends CamelCommand {
logTab.onTabSelected();
}
if (tab == TAB_HISTORY && ctx.selectedPid != null) {
- refreshHistoryData(List.of(Long.parseLong(ctx.selectedPid)));
- refreshTraceData(List.of(Long.parseLong(ctx.selectedPid)));
+ try {
+ long pid = Long.parseLong(ctx.selectedPid);
+ refreshHistoryData(List.of(pid));
+ refreshTraceData(List.of(pid));
+ } catch (NumberFormatException e) {
+ // ignore
+ }
historyTab.onTabSelected();
}
if (tab == TAB_CIRCUIT_BREAKER) {
@@ -2397,12 +2402,12 @@ public class CamelMonitor extends CamelCommand {
}
// Derive status from done/failed booleans
- Boolean done = (Boolean) json.get("done");
- Boolean failed = (Boolean) json.get("failed");
- entry.failed = Boolean.TRUE.equals(failed);
+ boolean done = Boolean.TRUE.equals(json.get("done"));
+ boolean failed = Boolean.TRUE.equals(json.get("failed"));
+ entry.failed = failed;
if (entry.failed) {
entry.status = "Failed";
- } else if (Boolean.TRUE.equals(done)) {
+ } else if (done) {
entry.status = "Done";
} else {
entry.status = "Processing";
@@ -2910,7 +2915,7 @@ public class CamelMonitor extends CamelCommand {
ci.className = cj.getString("class");
ci.scheduled = Boolean.TRUE.equals(cj.get("scheduled"));
ci.inflight = cj.getIntegerOrDefault("inflight", 0);
- ci.polling = (Boolean) cj.get("polling");
+ ci.polling = Boolean.TRUE.equals(cj.get("polling"));
ci.totalCounter = cj.getLong("totalCounter");
ci.delay = cj.getLong("delay");
ci.period = cj.getLong("period");