Skip to content

MessageHeaderAccessor doesn't remove headers if they are null [SPR-14468] #19037

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

Closed
spring-projects-issues opened this issue Jul 14, 2016 · 3 comments
Assignees
Labels
in: messaging Issues in messaging modules (jms, messaging) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Artem Bilan opened SPR-14468 and commented

The test-case to reproduce:

@Test
public void testRemoveEvenIfNull() {
	Message<?> message = new GenericMessage<>("payload", Collections.singletonMap("foo", null));
	MessageHeaderAccessor accessor = new MessageHeaderAccessor(message);
	accessor.removeHeader("foo");
	Map<String, Object> headers = accessor.toMap();
	assertFalse(headers.containsKey("foo"));
}

The workaround is only to extract a target Map and remove from there, and build a new Message.

But that doesn't help for Spring Integration's HeaderFilter to work properly.


Affects: 4.2.7, 4.3.1

Backported to: 4.2.8

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Good catch there! Even if MessageHeaderAccessor isn't really designed for storing null values there (implying that null means removal for its own accessor methods), it should properly handle them when encountered in the underlying Map.

@spring-projects-issues
Copy link
Collaborator Author

Artem Bilan commented

Perfect turnaround, Juergen :)!

Thank you!

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

You're welcome :-)

BTW, this is just in master at the moment. I'll backport it along with a few others tomorrow.

@spring-projects-issues spring-projects-issues added type: bug A general bug in: messaging Issues in messaging modules (jms, messaging) status: backported An issue that has been backported to maintenance branches labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.3.2 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: messaging Issues in messaging modules (jms, messaging) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants