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 1a90f44e5f8f CAMEL-23688: camel-console - the receive dev console 
dumps nothing when it has received nothing (#27980)
1a90f44e5f8f is described below

commit 1a90f44e5f8fd15c1b21baefd20af1190c87bd04
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Oct 17 00:30:10 2026 +0200

    CAMEL-23688: camel-console - the receive dev console dumps nothing when it 
has received nothing (#27980)
    
    The receive dev console took the timestamps of the first and last
    message of a dump without checking that there was a message, so a dump
    with nothing received yet, or since the last dump, failed with an
    IndexOutOfBoundsException. The CLI connector of an integration dumps it
    all the time, which failed (and was swallowed) whenever no message had
    come in, and a dump through the HTTP dev console failed. Found while
    testing camel cmd receive.
    
    Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
---
 .../camel/impl/console/ReceiveDevConsole.java      | 22 ++++++++++++++--------
 .../camel/impl/console/ReceiveDevConsoleTest.java  | 21 +++++++++++++++++++++
 2 files changed, 35 insertions(+), 8 deletions(-)

diff --git 
a/core/camel-console/src/main/java/org/apache/camel/impl/console/ReceiveDevConsole.java
 
b/core/camel-console/src/main/java/org/apache/camel/impl/console/ReceiveDevConsole.java
index 0c38c24a20ed..97a406aac315 100644
--- 
a/core/camel-console/src/main/java/org/apache/camel/impl/console/ReceiveDevConsole.java
+++ 
b/core/camel-console/src/main/java/org/apache/camel/impl/console/ReceiveDevConsole.java
@@ -164,10 +164,13 @@ public class ReceiveDevConsole extends AbstractDevConsole 
{
             if (removeOnDump) {
                 q.clear();
             }
-            JsonObject jo = (JsonObject) arr.get(0);
-            firstTimestamp = jo.getLongOrDefault("timestamp", 0);
-            jo = (JsonObject) arr.get(arr.size() - 1);
-            lastTimestamp = jo.getLongOrDefault("timestamp", 0);
+            // nothing may have been received since the last dump
+            if (!arr.isEmpty()) {
+                JsonObject jo = (JsonObject) arr.get(0);
+                firstTimestamp = jo.getLongOrDefault("timestamp", 0);
+                jo = (JsonObject) arr.get(arr.size() - 1);
+                lastTimestamp = jo.getLongOrDefault("timestamp", 0);
+            }
             String json = arr.toJson();
             sb.append(json).append("\n");
             return sb.toString();
@@ -216,10 +219,13 @@ public class ReceiveDevConsole extends AbstractDevConsole 
{
             if (removeOnDump) {
                 q.clear();
             }
-            JsonObject first = (JsonObject) messages.get(0);
-            firstTimestamp = first.getLongOrDefault("timestamp", 0);
-            JsonObject last = (JsonObject) messages.get(messages.size() - 1);
-            lastTimestamp = last.getLongOrDefault("timestamp", 0);
+            // nothing may have been received since the last dump
+            if (!messages.isEmpty()) {
+                JsonObject first = (JsonObject) messages.get(0);
+                firstTimestamp = first.getLongOrDefault("timestamp", 0);
+                JsonObject last = (JsonObject) messages.get(messages.size() - 
1);
+                lastTimestamp = last.getLongOrDefault("timestamp", 0);
+            }
 
             Response response = new Response(messages, null, null, null, null, 
null, null, null, null);
             return JsonRecordSupport.toJsonObject(response);
diff --git 
a/core/camel-console/src/test/java/org/apache/camel/impl/console/ReceiveDevConsoleTest.java
 
b/core/camel-console/src/test/java/org/apache/camel/impl/console/ReceiveDevConsoleTest.java
index c81502b34e4e..e869996ea626 100644
--- 
a/core/camel-console/src/test/java/org/apache/camel/impl/console/ReceiveDevConsoleTest.java
+++ 
b/core/camel-console/src/test/java/org/apache/camel/impl/console/ReceiveDevConsoleTest.java
@@ -16,10 +16,15 @@
  */
 package org.apache.camel.impl.console;
 
+import java.util.Collection;
+import java.util.Map;
+
 import org.apache.camel.console.DevConsole;
+import org.apache.camel.support.service.ServiceHelper;
 import org.apache.camel.util.json.JsonObject;
 import org.junit.jupiter.api.Test;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -40,4 +45,20 @@ public class ReceiveDevConsoleTest extends 
AbstractDevConsoleTest {
         assertNotNull(jsonOut.get("enabled"));
         assertNotNull(jsonOut.get("total"));
     }
+
+    @Test
+    public void testDumpWithoutMessages() {
+        DevConsole console = assertConsoleExists("receive", "camel");
+        // started, as the dev console registry of an application does
+        ServiceHelper.startService(console);
+
+        // nothing received yet, or since the last dump: the camel cli 
connector dumps all the time
+        String textOut = callText(console, Map.of("dump", "true"));
+        assertEquals("[]", textOut.trim());
+
+        JsonObject jsonOut = callJson(console, Map.of("dump", "true"));
+        Collection<?> messages = jsonOut.getCollection("messages");
+        assertNotNull(messages);
+        assertTrue(messages.isEmpty());
+    }
 }

Reply via email to