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 2b3c1d3d3e2a CAMEL-24885: camel-core - Simple: a resource: text with a
function but no scheme ends in a StackOverflowError
2b3c1d3d3e2a is described below
commit 2b3c1d3d3e2a508ae40735f780fa0610a969575d
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Sep 22 07:09:28 2026 +0200
CAMEL-24885: camel-core - Simple: a resource: text with a function but no
scheme ends in a StackOverflowError
Fixes https://issues.apache.org/jira/browse/CAMEL-24885
```yaml
- setBody:
simple: "resource:templates/${header.type}.json"
```
ended in a `StackOverflowError`: `LanguageSupport.isDynamicResource`
checked only the `resource:` prefix and a function, so
`SimpleLanguage.createExpression` returned the lazy dynamic expression; at
evaluation `ScriptHelper.resolveOptionalExternalScript`, which requires a
scheme, returned the text unchanged, `createExpression` was called with the
same text and returned the lazy expression again, without end.
`isDynamicResource` now uses the loader's own test
(`ScriptHelper.hasExternalScript`), so a scheme-less `resource:` text is a
plain expression, as it already was without a function.
`SimpleResourceWithoutSchemeTest` covers both cases and overflows without the
fix. Found while testing CAMEL-24884.
---
.../simple/SimpleResourceWithoutSchemeTest.java | 53 ++++++++++++++++++++++
.../org/apache/camel/support/LanguageSupport.java | 4 +-
2 files changed, 56 insertions(+), 1 deletion(-)
diff --git
a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleResourceWithoutSchemeTest.java
b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleResourceWithoutSchemeTest.java
new file mode 100644
index 000000000000..9e2f19a5954e
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleResourceWithoutSchemeTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.language.simple;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+/**
+ * CAMEL-24885: a resource: text with a function but no scheme is a plain
expression (it used to recurse into a
+ * StackOverflowError); with a scheme it is the dynamic resource it always was.
+ */
+public class SimpleResourceWithoutSchemeTest extends ContextTestSupport {
+
+ @Test
+ public void testWithoutASchemeItIsPlainText() throws Exception {
+
getMockEndpoint("mock:plain").expectedBodiesReceived("resource:templates/order.json");
+ template.sendBodyAndHeader("direct:plain", "x", "type", "order");
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testWithASchemeTheResourceIsLoaded() throws Exception {
+ getMockEndpoint("mock:dynamic").expectedBodiesReceived("The name is
x");
+ template.sendBodyAndHeader("direct:dynamic", "x", "name", "mysimple");
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("direct:plain").setBody(simple("resource:templates/${header.type}.json")).to("mock:plain");
+
from("direct:dynamic").setBody(simple("resource:classpath:${header.name}.txt")).to("mock:dynamic");
+ }
+ };
+ }
+}
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 dd7125bd096f..e52e8f99195d 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
@@ -91,7 +91,9 @@ public abstract class LanguageSupport implements Language,
IsSingleton, CamelCon
* Does the expression refer to a dynamic resource which uses simple
functions.
*/
protected boolean isDynamicResource(String expression) {
- return expression.startsWith(ResourceHelper.RESOURCE) &&
hasSimpleFunction(expression);
+ // the same test as the loader (ScriptHelper.hasExternalScript): a
resource: text without a scheme is not a
+ // resource, and treating it as one made Simple recurse into itself
(CAMEL-24885)
+ return ScriptHelper.hasExternalScript(expression) &&
hasSimpleFunction(expression);
}
/**