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 e06ae42eca13 CAMEL-25485: camel-jbang - the validator reports a
top-level ternary in a Simple expression that starts with resource: (#27598)
e06ae42eca13 is described below
commit e06ae42eca13b5cb0baadbe4948bcae86af6ce2e
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Oct 9 08:43:18 2026 +0200
CAMEL-25485: camel-jbang - the validator reports a top-level ternary in a
Simple expression that starts with resource: (#27598)
The check skipped every resource: expression, as its content is loaded from
a file. But the location is a template itself, so
resource:file:${exchangeProperty.CamelTimerCounter} == 1 ? a.json : b.json
has the ? and : as literal text, and the route failed with "Cannot load
resource file:2 == 1 ? a.json : b.json". The top-level ternary check of
CAMEL-24826 now runs on the location too.
Claude-Session: https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
---
.../dsl/jbang/core/commands/ai/SimpleChecks.java | 9 ++++++-
.../commands/ai/SourceValidatorSimpleTest.java | 31 ++++++++++++++++++++++
2 files changed, 39 insertions(+), 1 deletion(-)
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/SimpleChecks.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/SimpleChecks.java
index 77425ddd647c..d312ac576205 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/SimpleChecks.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/SimpleChecks.java
@@ -127,7 +127,14 @@ final class SimpleChecks {
List<String> errors, CamelCatalog catalog, String text, int
lineNum, boolean predicate, boolean logMessage,
boolean inAggregate) {
if (text.startsWith("resource:")) {
- // the expression is loaded from a file
(resource:classpath:script.txt), which is not the text here
+ // the expression is loaded from a file
(resource:classpath:script.txt), which is not the text here.
+ // The location is a template itself, so a ternary written in it
is still literal text (CAMEL-25485)
+ if (!predicate && !logMessage) {
+ String ternary = topLevelTernary(text);
+ if (ternary != null) {
+ errors.add("Line " + lineNum + ": " + ternary);
+ }
+ }
return;
}
boolean syntaxError = false;
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/SourceValidatorSimpleTest.java
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/SourceValidatorSimpleTest.java
index 9a16a68d2368..a2365b99a20a 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/SourceValidatorSimpleTest.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ai/SourceValidatorSimpleTest.java
@@ -434,6 +434,37 @@ class SourceValidatorSimpleTest {
.contains("inside one function");
}
+ @Test
+ void aTopLevelTernaryInAResourceLocationIsReported() {
+ // the location of resource: is a template, so the ? and : outside
${...} are literal text and the route
+ // fails with "Cannot load resource file:2 == 1 ? order.json :
order-bad-email.json" (CAMEL-25485)
+ List<String> msgs = SourceValidator.validateYamlSimple("""
+ - from:
+ uri: timer:tick
+ steps:
+ - setBody:
+ simple:
"resource:file:${exchangeProperty.CamelTimerCounter} == 1 ? order.json :
order-bad-email.json"
+ """, catalog);
+ assertThat(msgs).hasSize(1);
+ assertThat(msgs.get(0)).startsWith("Line 5:").contains("Simple has no
top-level ternary");
+ }
+
+ @Test
+ void aResourceLocationWithoutATopLevelTernaryIsAccepted() {
+ List<String> msgs = SourceValidator.validateYamlSimple(
+ """
+ - from:
+ uri: timer:tick
+ steps:
+ - setBody:
+ simple:
"resource:file:${exchangeProperty.CamelTimerCounter == 1 ? 'order.json' :
'order-bad-email.json'}"
+ - setBody:
+ simple: "resource:classpath:script.txt"
+ """,
+ catalog);
+ assertThat(msgs).isEmpty();
+ }
+
@Test
void aTernaryInsideOneFunctionIsAccepted() {
// the form that does evaluate the operator, so it must not be reported