gnodet opened a new pull request, #31271:
URL: https://github.com/apache/camel/pull/31271

   ## Summary
   
   Fix `camel-opentelemetry2` dev console incorrectly dumping spans when 
`dump=false` is passed, and prevent an `IllegalArgumentException` when a 
negative `limit` is supplied.
   
   ## Root Cause
   
   `OpenTelemetryDevConsole` used `optionString(options, DUMP)` to decide 
whether to dump spans, then checked `!= null`. Since `optionString` returns the 
raw string value, passing `dump=false` returns the non-null string `"false"`, 
which the null-check treats as truthy — triggering a full span dump even when 
the caller explicitly opted out.
   
   Separately, in `doCallJson`, if a negative `limit` value was passed (e.g. 
`limit=-1`), the expression `spans.size() - limit` could exceed `spans.size()`, 
making `subList(start, spans.size())` throw `IllegalArgumentException` 
(fromIndex > toIndex).
   
   ## Fix
   
   - Replace `optionString(options, DUMP)` with `optionBoolean(options, DUMP, 
false)` in both `doCallText()` and `doCallJson()`. `optionBoolean` correctly 
parses `"false"` → `false` via the Camel `TypeConverter`.
   - Clamp `limit` to `Math.max(0, ...)` before the `subList` call in 
`doCallJson()`.
   - Update the `@Metadata` annotation for the `dump` option from `javaType = 
"java.lang.String"` with an `enums` list to `javaType = "java.lang.Boolean"` 
with `defaultValue = "false"`, which matches the actual semantics and 
regenerates the JSON catalog correctly.
   
   ## Tests
   
   Three new regression tests in `OpenTelemetryDevConsoleTest`:
   
   - `testDumpFalseDoesNotDumpSpans` — asserts that `dump=false` returns the 
count/capacity summary (TEXT and JSON), not span data.
   - `testDumpTrueDumpsSpans` — asserts that `dump=true` returns the spans 
array.
   - `testNegativeLimitDoesNotThrow` — asserts that a negative `limit` does not 
throw.
   
   All 4 tests in the class pass locally.
   
   Fixes CAMEL-27987
   
   ---
   _Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_
   


-- 
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]

Reply via email to