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 bf9a6095a4cc CAMEL-24585: Fix catalog validateLanguageExpression NPE
for simple expressions using jsonpath/jq/xpath functions
bf9a6095a4cc is described below
commit bf9a6095a4ccf893e9ef53b5d3c9c4819af6f0ed
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Sep 2 18:13:26 2026 +0200
CAMEL-24585: Fix catalog validateLanguageExpression NPE for simple
expressions using jsonpath/jq/xpath functions
Guard LanguageSupport.property() against a null type converter so simple
expressions embedding a delegating language function (${jsonpath(...)},
${jq(...)}, ${xpath(...)}) validate against the bare tooling CamelContext
used by the catalog. When no type converter is available the value is
returned as-is, mirroring the existing camelContext == null branch;
runtime behavior is unchanged.
Closes #26036
Co-authored-by: Claude Opus 4.8 <[email protected]>
---
.../test/java/org/apache/camel/catalog/CamelCatalogTest.java | 12 ++++++++++++
.../main/java/org/apache/camel/support/LanguageSupport.java | 11 +++++++----
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git
a/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
b/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
index e7e22276e964..cc847e65b3c4 100644
---
a/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
+++
b/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
@@ -1243,6 +1243,18 @@ public class CamelCatalogTest {
assertEquals("$.store.book[?(@.price < 10)]", result.getText());
}
+ @Test
+ public void testValidateSimpleJSonPathFunction() {
+ // CAMEL-24585: a simple expression that delegates to the jsonpath
language must validate
+ // even though the tooling uses a bare CamelContext without a type
converter
+ LanguageValidationResult result =
catalog.validateLanguageExpression(null, "simple", "${jsonpath($.foo)}");
+ assertTrue(result.isSuccess());
+ assertEquals("${jsonpath($.foo)}", result.getText());
+
+ result = catalog.validateLanguagePredicate(null, "simple",
"${jsonpath($.store.book[?(@.price < 10)])} != null");
+ assertTrue(result.isSuccess());
+ }
+
@Test
public void testValidateJQLanguage() {
LanguageValidationResult result =
catalog.validateLanguagePredicate(null, "jq", ".foo == \"bar\"");
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/LanguageSupport.java
b/core/camel-support/src/main/java/org/apache/camel/support/LanguageSupport.java
index 0794b2d22d20..dd7125bd096f 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/LanguageSupport.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/LanguageSupport.java
@@ -24,6 +24,7 @@ import org.apache.camel.CamelContextAware;
import org.apache.camel.ExpressionIllegalSyntaxException;
import org.apache.camel.IsSingleton;
import org.apache.camel.NoSuchBeanException;
+import org.apache.camel.TypeConverter;
import org.apache.camel.spi.Language;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.TimeUtils;
@@ -176,11 +177,13 @@ public abstract class LanguageSupport implements
Language, IsSingleton, CamelCon
if (value == null) {
return null;
}
- if (camelContext != null) {
- return camelContext.getTypeConverter().convertTo(type, value);
- } else {
- return (T) value;
+ TypeConverter converter = camelContext != null ?
camelContext.getTypeConverter() : null;
+ if (converter != null) {
+ return converter.convertTo(type, value);
}
+ // no type converter is available (e.g. when using a bare CamelContext
for tooling/validation
+ // that has not been initialized) so return the value as-is
+ return (T) value;
}
}