-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fix exception message on StrictMap#put #2854
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
Conversation
tests are dependent on the message there so the tests would need updated as well. Please make sure to run full build before sending up code as this should have been obvious. Please make adjustments then this can be merged in. |
Ok, I will do this. |
The test case has been updated. |
The original message looks OK to me. |
The put method of the StrictMap class uses the containsKey method to determine whether the key is contained. If it is contained, it will throw "already contains value for " + key. This is not appropriate to describe the if condition. It should throw "already contains key for " + key, the original code is as follows @Override
@SuppressWarnings("unchecked")
public V put(String key, V value) {
if (containsKey(key)) {
throw new IllegalArgumentException(name + " already contains value for " + key
+ (conflictMessageProducer == null ? "" : conflictMessageProducer.apply(super.get(key), value)));
}
if (key.contains(".")) {
final String shortKey = getShortName(key);
if (super.get(shortKey) == null) {
super.put(shortKey, value);
} else {
super.put(shortKey, (V) new Ambiguity(shortKey));
}
}
return super.put(key, value);
} |
My English is not great, but "key for 'xxx'" is confusing, at least. It is either "a map contains value (or entry) for key 'xxx'" or simply "a map contains key 'xxx'". |
Ok, I think simply throw message "a map contains key 'xxx'" will better good. |
I thought the same, changes however do reflect the physical check its doing. Although, original didn't clearly indicate if 'value' was present just key is checked so technically it could be some other value... |
When key exists , the exception message
already contains value for...
is thrown,which is inappropriate and should be prompted for
already contains key for...
.