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

   # CAMEL-24262: guard nullable `awsErrorDetails()` when logging the AWS error 
code
   
   ## Motivation
   
   
`software.amazon.awssdk.awscore.exception.AwsServiceException#awsErrorDetails()`
 is **nullable**. Across the `camel-aws` producers, catch blocks log the AWS 
error code like this:
   
   ```java
   } catch (AwsServiceException ase) {
       LOG.trace("getFunction command returned the error code {}", 
ase.awsErrorDetails().errorCode());
       throw ase;
   }
   ```
   
   Because a method argument is evaluated **eagerly, regardless of the 
configured log level**, `ase.awsErrorDetails().errorCode()` runs even when 
`TRACE`/`DEBUG` is disabled. When `awsErrorDetails()` returns `null` (e.g. 
connection/SDK-level failures that are not a modeled service error), this 
throws a `NullPointerException` from inside the catch block, **masking the 
original AWS exception** that was about to be rethrown.
   
   ## Fix
   
   - Add a small null-safe helper 
`AwsExceptionUtil.errorCode(AwsServiceException)` in `camel-aws-common` 
(returns `null` when the exception or its `awsErrorDetails()` is absent).
   - Route every producer catch-block error-code log statement across the 
`camel-aws` components through it, replacing `x.awsErrorDetails().errorCode()` 
with `AwsExceptionUtil.errorCode(x)`.
   
   This is a defensive robustness fix: behaviour is unchanged on the happy path 
(the real error code is still logged), but a `null` `awsErrorDetails` can no 
longer shadow the underlying exception.
   
   ## Scope
   
   - New: `AwsExceptionUtil` + unit test in `camel-aws-common`.
   - 28 producers updated across 25 `camel-aws` modules (bedrock, comprehend, 
config, ec2, ecs, eks, eventbridge, iam, kinesis-firehose, kms, lambda, mq, 
msk, parameter-store, polly, redshift-data, rekognition, secrets-manager, 
security-hub, step-functions, sts, textract, timestream, transcribe, translate).
   - The `*ProducerHealthCheck` classes already guard this inline (CAMEL-24251) 
and are untouched.
   
   No public API change, no new dependency (the helper lives in the shared 
`camel-aws-common` that every producer already depends on).
   
   ## Testing
   
   - New hermetic unit test `AwsExceptionUtilTest` (3 cases: error code 
present, `awsErrorDetails` absent → `null`, `null` exception → `null`) — no 
LocalStack / real AWS.
   - Full reactor `mvn clean install -Dquickly` is green.
   
   Only targeting `main` (4.22.0) — low-severity, non-behavioural hardening.
   
   ---
   🤖 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