Skip to content

Fix NullPointerException in Kinesis binder CloudWatch client creation#1652

Open
kobeomseok95 wants to merge 1 commit into
awspring:mainfrom
kobeomseok95:fix-kinesis-binder-cloudwatch-customizer-npe
Open

Fix NullPointerException in Kinesis binder CloudWatch client creation#1652
kobeomseok95 wants to merge 1 commit into
awspring:mainfrom
kobeomseok95:fix-kinesis-binder-cloudwatch-customizer-npe

Conversation

@kobeomseok95

@kobeomseok95 kobeomseok95 commented Jul 17, 2026

Copy link
Copy Markdown

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

Fixes a NullPointerException in KinesisBinderConfiguration.cloudWatch() that occurs when spring.cloud.stream.kinesis.binder.kpl-kcl-enabled=true is set, the application has at least one input binding, and no AwsClientCustomizer<CloudWatchAsyncClientBuilder> bean is registered.

The method passed the optional customizer as Stream.of(configurer.getIfAvailable()), which produces a stream containing a single null element when the bean is absent, causing the NPE inside AwsClientBuilderConfigurer.configureAsyncClient(...). This change uses configurer.stream() instead, aligning cloudWatch() with the sibling client bean methods (amazonKinesis(), dynamoDB(), dynamoDBStreams()), and removes the now-unused java.util.stream.Stream import.

💡 Motivation and Context

Without this fix, enabling the KPL/KCL mode of the Kinesis binder requires registering a no-op AwsClientCustomizer<CloudWatchAsyncClientBuilder> bean as a workaround.

Fixes #1651

💚 How did you test it?

  • Added KinesisBinderConfigurationTests with two tests:
    • cloudWatchClientIsCreatedWhenNoCustomizerBeanIsRegistered — reproduces the reported NPE before the fix and passes after it
    • cloudWatchClientAppliesRegisteredCustomizer — verifies a registered customizer is still applied after the change
  • Ran the full spring-cloud-aws-kinesis-stream-binder test suite (LocalStack/Testcontainers based) — all 25 tests pass

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • I updated reference documentation to reflect the change (not needed — internal bugfix, no API or documented behavior change)
  • All tests passing
  • No breaking changes

🔮 Next steps

The bug is present in the released 4.0.x line (verified on 4.0.2), so this may be worth backporting to 4.0.x.

`KinesisBinderConfiguration.cloudWatch()` passed the optional
`AwsClientCustomizer` as `Stream.of(configurer.getIfAvailable())`, which
produces a stream with a single null element when no customizer bean is
defined and leads to a `NullPointerException` in
`AwsClientBuilderConfigurer.configureAsyncClient()`.

Use `configurer.stream()` instead, aligning with the sibling client bean
methods (`amazonKinesis()`, `dynamoDB()`, `dynamoDBStreams()`).

Fixes awspringgh-1651
@kobeomseok95 kobeomseok95 changed the title Fix NPE in Kinesis binder CloudWatch client creation Fix NullPointerException in Kinesis binder CloudWatch client creation Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NullPointerException when creating CloudWatchAsyncClient in Kinesis binder without an AwsClientCustomizer bean

1 participant