Skip to content

Commit 42304f5

Browse files
authored
Merge pull request #1876 from harawata/gh/1873-fix
Isolate result map parsing from parseStatement() to avoid possible IllegalArgumentException
2 parents 84af95f + 2d44833 commit 42304f5

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

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

Lines changed: 20 additions & 11 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) {
@@ -347,11 +354,13 @@ void parseStatement(Method method) {
347354
}
348355

349356
String resultMapId = null;
350-
ResultMap resultMapAnnotation = method.getAnnotation(ResultMap.class);
351-
if (resultMapAnnotation != null) {
352-
resultMapId = String.join(",", resultMapAnnotation.value());
353-
} else if (isSelect) {
354-
resultMapId = parseResultMap(method);
357+
if (isSelect) {
358+
ResultMap resultMapAnnotation = method.getAnnotation(ResultMap.class);
359+
if (resultMapAnnotation != null) {
360+
resultMapId = String.join(",", resultMapAnnotation.value());
361+
} else {
362+
resultMapId = generateResultMapName(method);
363+
}
355364
}
356365

357366
assistant.addMappedStatement(

src/test/java/org/apache/ibatis/submitted/resolution/javamethods/MapperA.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2018 the original author or authors.
2+
* Copyright 2009-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,4 +25,7 @@ public interface MapperA {
2525
@ResultMap("userRM")
2626
@Select("select * from users where id = #{id}")
2727
User getUser(Integer id);
28+
29+
@Select("select * from users")
30+
User getUser2(Integer id);
2831
}

0 commit comments

Comments
 (0)