-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
Hey Spring Team, thank you all for the great work you're doing! I kindly request to review the following proposition:
Currently, we have HttpHeaders class in the spring http package. That class defines the methods like add or addAll to add headers. Sometimes it really helps and become really useful. However, we recently faced a bug in production, that I think will explain the problem.
Imagine the following method:
public void addRedirectionIfNecessary(HttpHeaders headers) {
if (someCondition) {
headers.add(HttpHeaders.LOCATION, computeLocation());
}
}
The problem is that this code would not always work. Currently, nothing prevents a developer to either accidentally, or by totally innocent mistake pass here an instance of ReadOnlyHttpHeaders. The ReadOnlyHttpHeaders overrides the add/addAll methods and throws an UnsupportedOperationException.
This design resembles a Java Collection API. As admitted by Oracle, this is one of the most "controversial" decisions that was ever made in the Collections Framework design. Kotlin, for instance, that Spring Framework recently announced partnership with not that long ago, differentiates between mutable collections and immutable ones (like MutableList vs just List). I would take a responsibility to state, that, at least, based on my knowledge, the Kotlin's approach is generally considered to be superior of some sort in the industry since it prevents the kind of bugs that would otherwise happen.
I hope that this proposal makes sense and resonates for the core Spring team. I'll leave this issue as the placeholder for future discussions.