Skip to content

Commit 0239eda

Browse files
committed
also avoid package-info, interfaces and abstract classes in type handler scanning
1 parent 2d94ec8 commit 0239eda

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/main/java/org/apache/ibatis/type/TypeHandlerRegistry.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.apache.ibatis.io.ResolverUtil;
44

55
import java.lang.annotation.Annotation;
6+
import java.lang.reflect.Modifier;
67
import java.math.BigDecimal;
78
import java.math.BigInteger;
89
import java.util.Date;
@@ -184,13 +185,15 @@ public void register(String packageName) {
184185
ResolverUtil<Class<?>> resolverUtil = new ResolverUtil<Class<?>>();
185186
resolverUtil.find(new ResolverUtil.IsA(TypeHandler.class), packageName);
186187
Set<Class<? extends Class<?>>> handlerSet = resolverUtil.getClasses();
187-
188188
for (Class<?> type : handlerSet) {
189-
try {
190-
TypeHandler handler = (TypeHandler) type.getConstructor().newInstance();
191-
register(handler);
192-
} catch (Exception e) {
193-
throw new RuntimeException("Unable to find a usable constructor for " + type, e);
189+
//Ignore inner classes and interfaces (including package-info.java) and abstract classes
190+
if (!type.isAnonymousClass() && !type.isInterface() && !Modifier.isAbstract(type.getModifiers())) {
191+
try {
192+
TypeHandler handler = (TypeHandler) type.getConstructor().newInstance();
193+
register(handler);
194+
} catch (Exception e) {
195+
throw new RuntimeException("Unable to find a usable constructor for " + type, e);
196+
}
194197
}
195198
}
196199
}

0 commit comments

Comments
 (0)