You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Marco Bungart (Jira)" <ji...@apache.org> on 2025/04/01 21:54:00 UTC
[jira] [Created] (CAMEL-21926) camel-attachment: inconsistent behaviour
Marco Bungart created CAMEL-21926:
-------------------------------------
Summary: camel-attachment: inconsistent behaviour
Key: CAMEL-21926
URL: https://issues.apache.org/jira/browse/CAMEL-21926
Project: Camel
Issue Type: Bug
Components: camel-attachments
Affects Versions: 4.10.3, 4.10.2, 4.10.1
Reporter: Marco Bungart
Since camel {{4.10.1}}, the following code:
{code:java}
public class MyTimerRoute extends RouteBuilder {
@Override
public void configure() {
// @formatter:off
from(
timer("my-timer")
.fixedRate(true)
.period(Duration.ofSeconds(1).toMillis()))
.process(exchange -> {
AttachmentMessage message = exchange.getMessage(AttachmentMessage.class);
Path filePath = Files.createTempFile("attachment", "tmp");
message.addAttachment("foo", new DataHandler(new FileDataSource(filePath.toFile())));
})
.process(exchange -> {
AttachmentMessage message = exchange.getMessage(AttachmentMessage.class);
message.removeAttachment("foo");
boolean hasAttachments = message.hasAttachments();
exchange.setProperty("hasAttachments", hasAttachments);
exchange.setProperty("numAttachments", message.getAttachments().size());
})
.log("hasAttachment: ${exchangeProperty.hasAttachments}")
.log("# attachments: ${exchangeProperty.numAttachments}");
// @formatter:on
}
}
{code}
produces the following, inconsistent output:
{code}
...
[) thread #2 - timer://my-timer] route1 INFO hasAttachment: true
[) thread #2 - timer://my-timer] route1 INFO # attachments: 0
[) thread #2 - timer://my-timer] route1 INFO hasAttachment: true
[) thread #2 - timer://my-timer] route1 INFO # attachments: 0
[) thread #2 - timer://my-timer] route1 INFO hasAttachment: true
...
{code}
---
Reproducer:
1. Clone https://github.com/turing85/camel-attachment-bug:
{code:bash}
$ git clone https://github.com/turing85/camel-attachment-bug.git \
&& camel-attachment-bug
{code}
2. Notice that the camel version is set to {{4.10.1}}:
{code:bash}
$ grep -i '<camel.version>' pom.xml
<camel.version>4.10.1</camel.version>
{code}
3. build and start the application:
{code:bash}
$ mvn clean package && java -jar target/camel-attachment-bug-999-SNAPSHOT-executable-jar.jar
{code}
4. Notice the inconsistent output:
{code}
...
[ main] MainSupport INFO Apache Camel (Main) 4.10.0 is starting
[ main] BaseMainSupport INFO Classpath scanning enabled from base package: de.turing85.camel.attachment.bug
[ main] AbstractCamelContext INFO Apache Camel 4.10.0 (camel-1) is starting
[ main] AbstractCamelContext INFO Routes startup (total:1)
[ main] AbstractCamelContext INFO Started route1 (timer://my-timer)
[ main] AbstractCamelContext INFO Apache Camel 4.10.0 (camel-1) started in 8ms (build:0ms init:0ms start:8ms boot:395ms)
[) thread #2 - timer://my-timer] route1 INFO hasAttachment: false
[) thread #2 - timer://my-timer] route1 INFO # attachments: 0
...
{code}
5. Downgrade camel to {{4.10.0}}:
{code:bash}
$ sed -i 's@<camel\.version>.*@<camel.version>4.10.0</camel.version>@g' pom.xml \
&& grep -i '<camel.version>' pom.xml
<camel.version>4.10.0</camel.version>
{code}
6. Re-build and re-run the application:
{code:bash}
$ mvn clean package && java -jar target/camel-attachment-bug-999-SNAPSHOT-executable-jar.jar
{code}
7. Notice that the output shows consistent information
{code}
...
[ main] MainSupport INFO Apache Camel (Main) 4.10.0 is starting
[ main] BaseMainSupport INFO Classpath scanning enabled from base package: de.turing85.camel.attachment.bug
[ main] AbstractCamelContext INFO Apache Camel 4.10.0 (camel-1) is starting
[ main] AbstractCamelContext INFO Routes startup (total:1)
[ main] AbstractCamelContext INFO Started route1 (timer://my-timer)
[ main] AbstractCamelContext INFO Apache Camel 4.10.0 (camel-1) started in 9ms (build:0ms init:0ms start:9ms boot:380ms)
[) thread #2 - timer://my-timer] route1 INFO hasAttachment: false
[) thread #2 - timer://my-timer] route1 INFO # attachments: 0
[) thread #2 - timer://my-timer] route1 INFO hasAttachment: false
[) thread #2 - timer://my-timer] route1 INFO # attachments: 0
[) thread #2 - timer://my-timer] route1 INFO hasAttachment: false
[) thread #2 - timer://my-timer] route1 INFO # attachments: 0
...
{code}
---
FTR: https://camel.zulipchat.com/#narrow/channel/257298-camel/topic/camel.204.2E10.2E1.20and.20attachments
--
This message was sent by Atlassian Jira
(v8.20.10#820010)