1
1
/*
2
- * Copyright 2009-2024 the original author or authors.
2
+ * Copyright 2009-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
15
15
*/
16
16
package org .apache .ibatis .session ;
17
17
18
- import java .util .Arrays ;
19
- import java .util .Collection ;
20
- import java .util .HashMap ;
21
- import java .util .HashSet ;
22
- import java .util .Iterator ;
23
- import java .util .LinkedList ;
24
- import java .util .List ;
25
- import java .util .Map ;
26
- import java .util .Properties ;
27
- import java .util .Set ;
28
- import java .util .concurrent .ConcurrentHashMap ;
29
- import java .util .concurrent .locks .ReentrantLock ;
30
- import java .util .function .BiFunction ;
31
-
32
18
import org .apache .ibatis .binding .MapperRegistry ;
33
19
import org .apache .ibatis .builder .CacheRefResolver ;
34
20
import org .apache .ibatis .builder .IncompleteElementException ;
97
83
import org .apache .ibatis .type .TypeHandler ;
98
84
import org .apache .ibatis .type .TypeHandlerRegistry ;
99
85
86
+ import java .util .Arrays ;
87
+ import java .util .Collection ;
88
+ import java .util .HashMap ;
89
+ import java .util .HashSet ;
90
+ import java .util .Iterator ;
91
+ import java .util .LinkedList ;
92
+ import java .util .List ;
93
+ import java .util .Map ;
94
+ import java .util .Properties ;
95
+ import java .util .Set ;
96
+ import java .util .concurrent .ConcurrentHashMap ;
97
+ import java .util .concurrent .locks .ReentrantLock ;
98
+ import java .util .function .BiFunction ;
99
+
100
100
/**
101
101
* @author Clinton Begin
102
102
*/
@@ -1113,6 +1113,7 @@ protected static class StrictMap<V> extends ConcurrentHashMap<String, V> {
1113
1113
private static final long serialVersionUID = -4950446264854982944L ;
1114
1114
private final String name ;
1115
1115
private BiFunction <V , V , String > conflictMessageProducer ;
1116
+ private static final Object AMBIGUITY_INSTANCE = new Object ();
1116
1117
1117
1118
public StrictMap (String name , int initialCapacity , float loadFactor ) {
1118
1119
super (initialCapacity , loadFactor );
@@ -1162,7 +1163,7 @@ public V put(String key, V value) {
1162
1163
if (super .get (shortKey ) == null ) {
1163
1164
super .put (shortKey , value );
1164
1165
} else {
1165
- super .put (shortKey , (V ) new Ambiguity ( shortKey ) );
1166
+ super .put (shortKey , (V ) AMBIGUITY_INSTANCE );
1166
1167
}
1167
1168
}
1168
1169
return super .put (key , value );
@@ -1183,25 +1184,13 @@ public V get(Object key) {
1183
1184
if (value == null ) {
1184
1185
throw new IllegalArgumentException (name + " does not contain value for " + key );
1185
1186
}
1186
- if (value instanceof Ambiguity ) {
1187
- throw new IllegalArgumentException ((( Ambiguity ) value ). getSubject () + " is ambiguous in " + name
1187
+ if (AMBIGUITY_INSTANCE == value ) {
1188
+ throw new IllegalArgumentException (key + " is ambiguous in " + name
1188
1189
+ " (try using the full name including the namespace, or rename one of the entries)" );
1189
1190
}
1190
1191
return value ;
1191
1192
}
1192
1193
1193
- protected static class Ambiguity {
1194
- private final String subject ;
1195
-
1196
- public Ambiguity (String subject ) {
1197
- this .subject = subject ;
1198
- }
1199
-
1200
- public String getSubject () {
1201
- return subject ;
1202
- }
1203
- }
1204
-
1205
1194
private String getShortName (String key ) {
1206
1195
final String [] keyParts = key .split ("\\ ." );
1207
1196
return keyParts [keyParts .length - 1 ];
0 commit comments