Skip to content

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

Merged
merged 4 commits into from
Mar 20, 2023
Merged

Conversation

wayn111
Copy link
Contributor

@wayn111 wayn111 commented Mar 18, 2023

When key exists , the exception message already contains value for... is thrown,
which is inappropriate and should be prompted for already contains key for....

@hazendaz hazendaz self-assigned this Mar 18, 2023
@hazendaz
Copy link
Member

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.

@wayn111
Copy link
Contributor Author

wayn111 commented Mar 19, 2023

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.

@wayn111
Copy link
Contributor Author

wayn111 commented Mar 19, 2023

The test case has been updated.

@harawata
Copy link
Member

The original message looks OK to me.
If we want to make it super explicit, it can be "... already contains value for key 'xxx'", maybe.

@wayn111
Copy link
Contributor Author

wayn111 commented Mar 19, 2023

The original message looks OK to me.
If we want to make it super explicit, it can be "... already contains value for key 'xxx'", maybe.

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);
    }

@harawata
Copy link
Member

My English is not great, but "key for 'xxx'" is confusing, at least.
"a map contains key for 'xxx'" implies 'xxx' is a value.

It is either "a map contains value (or entry) for key 'xxx'" or simply "a map contains key 'xxx'".

@wayn111
Copy link
Contributor Author

wayn111 commented Mar 19, 2023

My English is not great, but "key for 'xxx'" is confusing, at least. "a map contains key for 'xxx'" implies 'xxx' is a value.

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.

@hazendaz
Copy link
Member

hazendaz commented Mar 19, 2023

The original message looks OK to me. If we want to make it super explicit, it can be "... already contains value for key 'xxx'", maybe.

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...

@coveralls
Copy link

Coverage Status

Coverage: 87.545% (-0.009%) from 87.555% when pulling e5d74e0 on wayn111:master into 9e43552 on mybatis:master.

@hazendaz hazendaz merged commit c9137b0 into mybatis:master Mar 20, 2023
@kazuki43zoo kazuki43zoo added the polishing Improve a implementation code or doc without change in current behavior/content label May 13, 2023
@kazuki43zoo kazuki43zoo added this to the 3.5.14 milestone May 13, 2023
@kazuki43zoo kazuki43zoo changed the title Modify Comments: Configuration.StrictMap<V> put(String key, V value) … Fix exception message on StrictMap#put May 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
polishing Improve a implementation code or doc without change in current behavior/content
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants