Skip to content

Commit 2e9632d

Browse files
authored
Merge pull request #1617 from kazuki43zoo/gh-1616
Prevent infinite loop when throw Exception that hold cause from provider method
2 parents 20b6152 + 729a1ef commit 2e9632d

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private SqlSource createSqlSource(Object parameterObject) {
173173
private Throwable extractRootCause(Exception e) {
174174
Throwable cause = e;
175175
while(cause.getCause() != null) {
176-
cause = e.getCause();
176+
cause = cause.getCause();
177177
}
178178
return cause;
179179
}

src/test/java/org/apache/ibatis/submitted/sqlprovider/SqlProviderTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import static org.junit.jupiter.api.Assertions.fail;
2323

2424
import java.io.Reader;
25-
import java.lang.annotation.Annotation;
2625
import java.lang.reflect.Method;
2726
import java.util.ArrayList;
2827
import java.util.Collections;
@@ -391,6 +390,20 @@ void invokeError() throws NoSuchMethodException {
391390
}
392391
}
393392

393+
@Test
394+
void invokeNestedError() throws NoSuchMethodException {
395+
try {
396+
Class<?> mapperType = ErrorMapper.class;
397+
Method mapperMethod = mapperType.getMethod("invokeNestedError");
398+
new ProviderSqlSource(new Configuration(),
399+
mapperMethod.getAnnotation(SelectProvider.class), mapperType, mapperMethod)
400+
.getBoundSql(new Object());
401+
fail();
402+
} catch (BuilderException e) {
403+
assertTrue(e.getMessage().contains("Error invoking SqlProvider method 'public java.lang.String org.apache.ibatis.submitted.sqlprovider.SqlProviderTest$ErrorSqlBuilder.invokeNestedError()' with specify parameter 'class java.lang.Object'. Cause: java.lang.UnsupportedOperationException: invokeNestedError"));
404+
}
405+
}
406+
394407
@Test
395408
void invalidArgumentsCombination() throws NoSuchMethodException {
396409
try {
@@ -670,6 +683,9 @@ public interface ErrorMapper {
670683
@SelectProvider(type = ErrorSqlBuilder.class, method = "invokeError")
671684
void invokeError();
672685

686+
@SelectProvider(type = ErrorSqlBuilder.class, method = "invokeNestedError")
687+
void invokeNestedError();
688+
673689
@SelectProvider(type = ErrorSqlBuilder.class, method = "multipleProviderContext")
674690
void multipleProviderContext();
675691

@@ -702,6 +718,10 @@ public String invokeError() {
702718
throw new UnsupportedOperationException("invokeError");
703719
}
704720

721+
public String invokeNestedError() {
722+
throw new IllegalStateException(new UnsupportedOperationException("invokeNestedError"));
723+
}
724+
705725
public String multipleProviderContext(ProviderContext providerContext1, ProviderContext providerContext2) {
706726
throw new UnsupportedOperationException("multipleProviderContext");
707727
}

0 commit comments

Comments
 (0)