You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Claus Ibsen (Jira)" <ji...@apache.org> on 2022/09/01 05:14:00 UTC
[jira] [Commented] (CAMEL-18443) Problem using AdviceWith on routes with try-catch-finally
[ https://issues.apache.org/jira/browse/CAMEL-18443?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17598743#comment-17598743 ]
Claus Ibsen commented on CAMEL-18443:
-------------------------------------
Thanks for reporting and providing unit test sample.
> Problem using AdviceWith on routes with try-catch-finally
> ---------------------------------------------------------
>
> Key: CAMEL-18443
> URL: https://issues.apache.org/jira/browse/CAMEL-18443
> Project: Camel
> Issue Type: Bug
> Components: camel-test
> Affects Versions: 3.18.1
> Reporter: Lars Haugaard Kristensen
> Assignee: Claus Ibsen
> Priority: Minor
> Fix For: 3.18.2, 3.19.0
>
>
> When upgrading to 3.18.1 I see a problem with some of my project's existing tests that break. I've isolated the problem to tests that use AdviceWith on routes that make use of try-catch-finally.
> Here is a test that succeeds in 3.18.0 but fails in 3.18.1:
> {code:java}
> import static org.apache.camel.builder.AdviceWith.adviceWith;
> import org.apache.camel.RoutesBuilder;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.test.junit5.CamelTestSupport;
> import org.junit.jupiter.api.Test;
> public class TryCatchFinallyTest extends CamelTestSupport {
> @Test
> public void tryCatchFinallyUsingAdviceWith() throws Exception {
> adviceWith(context, "my-route", a ->
> a.weaveById("replace-me")
> .replace()
> .to("mock:replaced")
> );
> context.start();
> }
>
> @Override
> public boolean isUseAdviceWith() {
> return true;
> }
>
> @Override
> protected RoutesBuilder createRouteBuilder() {
> return new RouteBuilder() {
> @Override
> public void configure() {
> from("direct:start")
> .routeId("my-route")
> .doTry()
> .log("try")
> .to("mock:replace-me").id("replace-me")
> .doCatch(Exception.class)
> .log("catch")
> .doFinally()
> .log("finally")
> .end();
> }
> };
> }
>
> } {code}
> The stack trace:
> {noformat}
> Failed to create route my-route at: >>> DoTry[[Log[try], To[mock:replaced], DoCatch[ [class java.lang.Exception] -> [Log[catch]]], DoFinally[[Log[finally]]]]] <<< in route: Route(my-route)[From[direct:start] -> [DoTry[[Log[try], To[m... because of Multiple finally clauses added: DoFinally[[Log[finally]]] and DoFinally[[Log[finally]]]
> org.apache.camel.FailedToCreateRouteException: Failed to create route my-route at: >>> DoTry[[Log[try], To[mock:replaced], DoCatch[ [class java.lang.Exception] -> [Log[catch]]], DoFinally[[Log[finally]]]]] <<< in route: Route(my-route)[From[direct:start] -> [DoTry[[Log[try], To[m... because of Multiple finally clauses added: DoFinally[[Log[finally]]] and DoFinally[[Log[finally]]]
> at app//org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:240)
> at app//org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:74)
> at app//org.apache.camel.impl.DefaultModelReifierFactory.createRoute(DefaultModelReifierFactory.java:49)
> at app//org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:862)
> at app//org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:750)
> at app//org.apache.camel.impl.engine.AbstractCamelContext.doInit(AbstractCamelContext.java:2947)
> at app//org.apache.camel.support.service.BaseService.init(BaseService.java:83)
> at app//org.apache.camel.impl.engine.AbstractCamelContext.init(AbstractCamelContext.java:2630)
> at app//org.apache.camel.support.service.BaseService.start(BaseService.java:111)
> at app//org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2649)
> at app//org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:262)
> at app//TryCatchFinallyTest.tryCatchFinallyUsingAdviceWith(TryCatchFinallyTest.java:18)
> at java.base@11.0.16/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at java.base@11.0.16/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at java.base@11.0.16/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.base@11.0.16/java.lang.reflect.Method.invoke(Method.java:566)
> at app//org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)
> at app//org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
> at app//org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
> at app//org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
> at app//org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
> at app//org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
> at app//org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
> at app//org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
> at app//org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
> at app//org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
> at app//org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
> at app//org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
> at app//org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
> at app//org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
> at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:214)
> at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
> at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:210)
> at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
> at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66)
> at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
> at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
> at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
> at app//org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
> at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
> at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
> at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
> at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
> at java.base@11.0.16/java.util.ArrayList.forEach(ArrayList.java:1541)
> at app//org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
> at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
> at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
> at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
> at app//org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
> at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
> at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
> at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
> at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
> at java.base@11.0.16/java.util.ArrayList.forEach(ArrayList.java:1541)
> at app//org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
> at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
> at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
> at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
> at app//org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
> at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
> at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
> at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
> at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
> at app//org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
> at app//org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
> at app//org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
> at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)
> at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
> at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
> at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
> at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
> at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)
> at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)
> at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
> at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
> at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
> at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
> at java.base@11.0.16/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at java.base@11.0.16/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at java.base@11.0.16/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.base@11.0.16/java.lang.reflect.Method.invoke(Method.java:566)
> at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
> at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
> at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
> at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
> at com.sun.proxy.$Proxy2.stop(Unknown Source)
> at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
> at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
> at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
> at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
> at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
> at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133)
> at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
> at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
> at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
> Caused by: java.lang.IllegalArgumentException: Multiple finally clauses added: DoFinally[[Log[finally]]] and DoFinally[[Log[finally]]]
> at org.apache.camel.model.TryDefinition.checkInitialized(TryDefinition.java:225)
> at org.apache.camel.model.TryDefinition.preCreateProcessor(TryDefinition.java:207)
> at org.apache.camel.reifier.ProcessorReifier.preCreateProcessor(ProcessorReifier.java:870)
> at org.apache.camel.reifier.ProcessorReifier.makeProcessor(ProcessorReifier.java:838)
> at org.apache.camel.reifier.ProcessorReifier.addRoutes(ProcessorReifier.java:588)
> at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:236)
> ... 94 more
> {noformat}
> The test succeeds if I skip using AdviceWith.
> I see there was a change to the TryDefinition class in 3.18.1 (CAMEL-18288) but I'm not sure that's the cause.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)