Skip to content

Commit 7965e6a

Browse files
committed
fixes #1874 CacheNamespaceRef causes IllegalArgumentException depending on the mapper order
As described in the report, `parseStatement()` actually parses result maps before parsing statement. When parsing result map succeeds and parsing statement fails, `parseStatement()` tries to re-adding the same result map in the re-try phase and causes IllegalArgumentException. This fix is isolating result map parsing from `parseStatement()`.
1 parent 149c0cc commit 7965e6a

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,15 @@ public void parse() {
130130
assistant.setCurrentNamespace(type.getName());
131131
parseCache();
132132
parseCacheRef();
133-
Method[] methods = type.getMethods();
134-
for (Method method : methods) {
133+
for (Method method : type.getMethods()) {
134+
if (!canHaveStatement(method)) {
135+
continue;
136+
}
137+
if (getSqlCommandType(method) == SqlCommandType.SELECT && method.getAnnotation(ResultMap.class) == null) {
138+
parseResultMap(method);
139+
}
135140
try {
136-
// issue #237
137-
if (!method.isBridge()) {
138-
parseStatement(method);
139-
}
141+
parseStatement(method);
140142
} catch (IncompleteElementException e) {
141143
configuration.addIncompleteMethod(new MethodResolver(this, method));
142144
}
@@ -145,6 +147,11 @@ public void parse() {
145147
parsePendingMethods();
146148
}
147149

150+
private boolean canHaveStatement(Method method) {
151+
// issue #237
152+
return !method.isBridge() && !method.isDefault();
153+
}
154+
148155
private void parsePendingMethods() {
149156
Collection<MethodResolver> incompleteMethods = configuration.getIncompleteMethods();
150157
synchronized (incompleteMethods) {
@@ -351,7 +358,7 @@ void parseStatement(Method method) {
351358
if (resultMapAnnotation != null) {
352359
resultMapId = String.join(",", resultMapAnnotation.value());
353360
} else if (isSelect) {
354-
resultMapId = parseResultMap(method);
361+
resultMapId = generateResultMapName(method);
355362
}
356363

357364
assistant.addMappedStatement(

0 commit comments

Comments
 (0)