gnodet-bot commented on code in PR #31172:
URL: https://github.com/apache/camel/pull/31172#discussion_r4758950894


##########
components/camel-seda/src/main/java/org/apache/camel/component/seda/SedaComponent.java:
##########
@@ -163,9 +167,15 @@ public QueueReference getOrCreateQueue(
             // create queue
             BlockingQueue<Exchange> queue;
             BlockingQueueFactory<Exchange> queueFactory = customQueueFactory 
== null ? defaultQueueFactory : customQueueFactory;
-            if (size != null && size > 0) {
+            if (size != null && size > 0 && size < Integer.MAX_VALUE) {
+                // bounded queue with an explicit size that is not MAX_VALUE
                 queue = queueFactory.create(size);
+            } else if (size != null && size == Integer.MAX_VALUE) {
+                // explicitly unbounded (size=MAX_VALUE): bypass the component 
queueSize default
+                size = null; // null in QueueReference means unbounded

Review Comment:
   ⚠️ **One-sided sharing check — `size=MAX_VALUE` on an endpoint silently 
attaches to an existing bounded queue.**
   
   When an endpoint with `size=MAX_VALUE` calls `getOrCreateQueue` and a 
bounded queue (e.g. `ref.getSize() == 500`) already exists for the same key, 
the flow is:
   
   1. `explicitlyUnbounded = true`, `size = null` (reset here, before the 
size-mismatch check)
   2. `ref != null`, the check is `size != null && …` → `null != null` = false 
→ **check skipped**
   3. The endpoint reuses the bounded-500 queue silently, even though the user 
asked for an unbounded queue
   
   This is CAMEL-27896 item 1 in reverse: an explicit `size=MAX_VALUE` on a 
*second* endpoint that joins an existing bounded queue should throw "cannot use 
existing bounded queue of size 500 as unbounded (MAX_VALUE)". Instead it 
silently reuses the wrong queue.
   
   The normalised-comparison fix above (`size != existing` with `existing = 
ref.getSize() != null ? ref.getSize() : MAX_VALUE`) handles this automatically: 
`MAX_VALUE != 500` → IAE, as expected.



##########
components/camel-seda/src/main/java/org/apache/camel/component/seda/SedaComponent.java:
##########
@@ -144,12 +144,16 @@ public QueueReference getOrCreateQueue(
             QueueReference ref = getQueues().get(key);
             if (ref != null) {
                 // if the given size is not provided, we just use the existing 
queue as is

Review Comment:
   ⚠️ **Startup regression — `customSize` still stores `MAX_VALUE` and breaks 
sizeless endpoints.**
   
   When `from("seda:foo?size=2147483647")` is defined before context start, 
`createEndpoint` runs `setSize(MAX_VALUE)` (setting `sizeSet=true`) and then 
stores `customSize.put("seda://foo", MAX_VALUE)` (line ~282 of 
`SedaComponent`). This `customSize` entry survives until `doStop()`.
   
   Later, a sizeless endpoint — e.g. `to("seda:foo")` or 
`template.sendBody("seda:foo", …)` — calls `getOrCreateQueue` with `size=null` 
(because `sizeSet=false`). It enters this block:
   
   ```java
   if (size == null && !explicitlyUnbounded) {
       size = customSize.get(key);  // ← returns MAX_VALUE from the from() 
endpoint's registration
   }
   ```
   
   Now `size = MAX_VALUE`. The existing unbounded queue has `ref.getSize() == 
null`. The unchanged check at line ~171:
   
   ```java
   if (size != null && !size.equals(ref.getSize()))
       throw new IllegalArgumentException("Cannot use existing queue …");
   ```
   
   fires: `MAX_VALUE != null` → `MAX_VALUE.equals(null)` is false → **IAE 
thrown**, even though both endpoints mean "unbounded".
   
   **Fix (davsclaus's suggestion):** normalise `null` ref size to `MAX_VALUE` 
in the comparison:
   
   ```java
   int existing = ref.getSize() != null ? ref.getSize() : Integer.MAX_VALUE;
   if (size != null && size != existing)
       throw new IllegalArgumentException(
           "Cannot use existing queue " + key + " as the existing queue size "
           + existing + " does not match given queue size " + size);
   ```
   
   This also makes the error message accurate for unbounded queues (reports 
`MAX_VALUE` instead of the fallback `1000`), and the `explicitlyUnbounded` 
branch on the creation side can be removed — `MAX_VALUE` travels through as an 
ordinary size and `queueFactory.create(MAX_VALUE)` creates a bounded 
`LinkedBlockingQueue(MAX_VALUE)`, which the JDK itself uses as "practically 
unbounded". Alternatively, keep `explicitlyUnbounded` and add an explicit 
guard: skip the existing-queue size check when both sides are unbounded (`size 
== MAX_VALUE && ref.getSize() == null`).
   
   `SameSedaQueueSizeAndNoSizeTest` with `size=2147483647` (as davsclaus 
suggested) would catch this regression.



##########
docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc:
##########
@@ -189,6 +189,24 @@ starts, the same error that was already raised when the 
endpoint was still activ
 queue was silently replaced with a fresh one,
 which caused the buffered messages to be discarded.
 
+=== camel-seda - size and concurrentConsumers sentinel values are now respected
+
+Two sentinel-value ambiguities in the SEDA component are fixed:
+
+* `size=1000` (the SEDA default) or `size=2147483647` (`Integer.MAX_VALUE`) 
explicitly set on an endpoint URI are
+now recognised as a user choice and respected. Previously these values were 
treated as "not set" and silently
+replaced by the component default. With this fix, an explicit `size=1000` 
creates a queue of capacity 1000, and
+an explicit `size=2147483647` creates an unbounded queue, regardless of the 
component's default queue size.
+An endpoint that specifies a `size` that conflicts with the already-created 
queue of the same name now fails with

Review Comment:
   🔧 **Upgrade guide — misleading migration instruction.**
   
   > _"must now set the queue size to a value other than 1000 or 
`Integer.MAX_VALUE` to get a different capacity, or omit the `size` option 
entirely."_
   
   This sentence reads as if users must actively change their `size` values 
away from 1000 or `MAX_VALUE`. The actual migration guidance is the opposite: 
users who previously omitted `size` (or whose tooling implicitly set it to 
1000/MAX_VALUE as a default) now need to either keep those as explicit values 
(and they'll be honoured) or omit `size` to let the component default apply.
   
   A cleaner rewrite:
   
   ```suggestion
   default, which could cause an `IllegalArgumentException` ("Cannot use 
existing queue … does not match") when a
   second endpoint joined a queue whose size was implicitly overridden.
   If your deployment relied on `size=1000` or `size=2147483647` being silently 
ignored, those values are now
   respected; remove the `size` option from the URI if you want the 
component-level default to apply.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to