TimurRakhmatullin86 opened a new pull request, #26871:
URL: https://github.com/apache/camel/pull/26871

   ## Summary
   
   When catching `InterruptedException`, the interrupt flag on the current 
thread is cleared by the JVM. If the catch block does not call 
`Thread.currentThread().interrupt()` to restore the flag, upstream code 
(callers, thread pools, shutdown hooks) cannot detect that an interrupt 
occurred. This is a well-documented Java concurrency best practice (see *Java 
Concurrency in Practice* ยง7.1.3, Sonar rule 
[S2142](https://rules.sonarsource.com/java/RSPEC-S2142)).
   
   This PR adds the missing `Thread.currentThread().interrupt()` call to 8 
catch sites across 6 files in 5 modules:
   
   ### Files changed
   
   | Module | File | Fix |
   |--------|------|-----|
   | `camel-core-processor` | `ConcurrentRequestsThrottler.java` | Added 
`Thread.currentThread().interrupt()` before `handleInterrupt()` call |
   | `camel-aws2-kinesis` | `KclKinesis2Consumer.java` | Added 
`Thread.currentThread().interrupt()` before debug log during graceful shutdown |
   | `camel-smpp` | `MessageReceiverListenerImpl.java` | Added 
`Thread.currentThread().interrupt()` in 3 catch blocks that previously silently 
swallowed the interrupt (`// ignore`) |
   | `camel-tahu` | `TahuEdgeClient.java` | Added 
`Thread.currentThread().interrupt()` in multi-catch block during client 
shutdown |
   | `camel-cli-debug` | `CamelCliDebuggerFactory.java` | Added 
`Thread.currentThread().interrupt()` before early return |
   | `camel-jbang-plugin-kubernetes` | `KubernetesPodLogs.java` | Added 
`Thread.currentThread().interrupt()` before printing interrupt message |
   
   ### Approach
   
   - Only catch blocks that (a) catch `InterruptedException`, (b) do **not** 
already call `Thread.currentThread().interrupt()`, and (c) do **not** rethrow 
the exception were modified.
   - The `Thread.currentThread().interrupt()` call is placed as the first 
statement in each catch block, before any logging or other handling, following 
the standard idiom.
   - For multi-catch blocks (e.g., `CancellationException | ExecutionException 
| InterruptedException`), the block is kept as-is and 
`Thread.currentThread().interrupt()` is added โ€” calling `interrupt()` is 
harmless when the caught exception is not an `InterruptedException`.
   
   ### How I verified
   
   I audited all `catch (InterruptedException ...)` sites in production code 
(`src/main/java`) across the entire repository. The vast majority already 
correctly restore the interrupt flag โ€” credit to the existing maintainers. 
These 8 sites are the ones that were missing the restoration.
   
   ๐Ÿค– Generated with [Claude Code](https://claude.com/claude-code)


-- 
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