CAMEL-24262: camel-aws2 - guard nullable awsErrorDetails() when logging the AWS error code in producer catch blocks - #25324
Merged
Conversation
…ng the AWS error code in producer catch blocks
AwsServiceException.awsErrorDetails() is nullable, so producer catch-block
log statements of the form LOG.trace("...{}", e.awsErrorDetails().errorCode())
can throw a NullPointerException that masks the original AWS exception - the
argument is evaluated eagerly regardless of the configured log level.
Add a small AwsExceptionUtil.errorCode(AwsServiceException) helper in
camel-aws-common that reads the error code defensively (null-safe on both the
exception and its awsErrorDetails), and route all producer catch-block
error-code logging across the camel-aws components through it.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
davsclaus
approved these changes
Aug 4, 2026
Contributor
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
Contributor
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 43 tested, 29 compile-only — current: 43 all testedMaveniverse Scalpel detected 72 affected modules (current approach: 43).
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CAMEL-24262: guard nullable
awsErrorDetails()when logging the AWS error codeMotivation
software.amazon.awssdk.awscore.exception.AwsServiceException#awsErrorDetails()is nullable. Across thecamel-awsproducers, catch blocks log the AWS error code like this:Because a method argument is evaluated eagerly, regardless of the configured log level,
ase.awsErrorDetails().errorCode()runs even whenTRACE/DEBUGis disabled. WhenawsErrorDetails()returnsnull(e.g. connection/SDK-level failures that are not a modeled service error), this throws aNullPointerExceptionfrom inside the catch block, masking the original AWS exception that was about to be rethrown.Fix
AwsExceptionUtil.errorCode(AwsServiceException)incamel-aws-common(returnsnullwhen the exception or itsawsErrorDetails()is absent).camel-awscomponents through it, replacingx.awsErrorDetails().errorCode()withAwsExceptionUtil.errorCode(x).This is a defensive robustness fix: behaviour is unchanged on the happy path (the real error code is still logged), but a
nullawsErrorDetailscan no longer shadow the underlying exception.Scope
AwsExceptionUtil+ unit test incamel-aws-common.camel-awsmodules (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).*ProducerHealthCheckclasses already guard this inline (CAMEL-24251) and are untouched.No public API change, no new dependency (the helper lives in the shared
camel-aws-commonthat every producer already depends on).Testing
AwsExceptionUtilTest(3 cases: error code present,awsErrorDetailsabsent →null,nullexception →null) — no LocalStack / real AWS.mvn clean install -Dquicklyis green.Only targeting
main(4.22.0) — low-severity, non-behavioural hardening.🤖 Generated with Claude Code