Skip to content

Conversation

@jkaving
Copy link
Contributor

@jkaving jkaving commented Feb 4, 2025

Fixes #2949

The handling of retryCount is moved into convertHeadersIfNecessary(), so that we can still return a Collections.emptyMap() if there are no headers in the source MessageProperties and no retryCount to add.

Fixes spring-projects#2949

The handling of retryCount is moved into convertHeadersIfNecessary(),
so that we can still return a Collections.emptyMap() if there are no headers
in the source MessageProperties and no retryCount to add.

Signed-off-by: Johan Kaving <[email protected]>
Comment on lines -158 to -162
Map<String, Object> headers = convertHeadersIfNecessary(source.getHeaders());
long retryCount = source.getRetryCount();
if (retryCount > 0) {
headers.put(MessageProperties.RETRY_COUNT, retryCount);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative solution could be to keep the retryCount code here, but add some kind of check inside the if (retryCount > 0) block.

We could e.g., check if headers is empty:

...
if (retryCount > 0) {
	if (headers.isEmpty()) {
		headers = new HashMap<>();
	}
	headers.put(MessageProperties.RETRY_COUNT, retryCount);
}
...

or catch the exception:

...
if (retryCount > 0) {
	try {
		headers.put(MessageProperties.RETRY_COUNT, retryCount);
	} catch (UnsupportedOperationException e) {
		headers = Map.of(MessageProperties.RETRY_COUNT, retryCount);
	}
}
...

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm fine with what you did so far: less objects is better.

Sorry about missing the case when map of headers could be empty.

Will merge when the build is green.

Thank you!

@artembilan artembilan merged commit f621b86 into spring-projects:main Feb 4, 2025
3 checks passed
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.

Using retryCount results in UnsupportedOperationException

2 participants