Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch SnsNotification is deserialized into incorrect type when using generics #1280

Open
frjonsen opened this issue Nov 20, 2024 · 0 comments
Labels
component: sqs SQS integration related issue type: enhancement Smaller enhancement in existing integration

Comments

@frjonsen
Copy link

Type: Bug

Component:
SQS

Describe the bug
While working on a PR for #1272 I noticed batches are not working properly when using @SnsNotificationMessage, such as whencreating a listener which takes @SnsNotificationMessage List<MyEnvelope<MyPojo>>. It actually ends up deserializing into a List<MyEnvelope<LinkedHashMap>>.

Sample
The easiest way to reproduce this is by extending the listener for the existing test for the SNS integration, found here.

By adding an assert for the value contents, the test starts failing:

@SqsListener(queueNames = RESOLVES_POJO_FROM_NOTIFICATION_MESSAGE_LIST_QUEUE_NAME, id = "resolves-pojo-with-notification-message-list", factory = "defaultSqsListenerContainerFactory")
void listen(@SnsNotificationMessage List<MyEnvelope<MyPojo>> myPojos) {
	Assert.notEmpty(myPojos, "Received empty messages");
	logger.debug("Received messages {} from queue {}", myPojos,
			RESOLVES_POJO_FROM_NOTIFICATION_MESSAGE_LIST_QUEUE_NAME);

	for (MyEnvelope<MyPojo> myPojo : myPojos) {
		assertThat(myPojo.getData().getFirstField()).isEqualTo("pojoNotificationMessage");
	}
	latchContainer.resolvesPojoNotificationMessageListLatch.countDown();
}

The following error is output to the terminal:

Caused by: java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class io.awspring.cloud.sqs.integration.SqsMessageConversionIntegrationTests$MyPojo (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; io.awspring.cloud.sqs.integration.SqsMessageConversionIntegrationTests$MyPojo is in unnamed module of loader 'app')
	at io.awspring.cloud.sqs.integration.SqsMessageConversionIntegrationTests$ResolvesPojoWithNotificationAnnotationListener.listen(SqsMessageConversionIntegrationTests.java:291)

It appears that even though the parameter of the function is List<MyEnvelope<MyPojo>>, the actual cast is not executed until there is an attempt to access the members of the target class, and as the test only checks if the list contains any items, it erroneously passes.

@maciejwalkowiak maciejwalkowiak added component: sqs SQS integration related issue type: enhancement Smaller enhancement in existing integration labels Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: sqs SQS integration related issue type: enhancement Smaller enhancement in existing integration
Projects
None yet
Development

No branches or pull requests

2 participants