Skip to content

Commit 9ce5260

Browse files
committed
fixes #1177 Calling TypeHandlerRegistry#hasTypeHandler() prevents subsequent regiser() from working properly.
1 parent 21377c9 commit 9ce5260

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2017 the original author or authors.
2+
* Copyright 2009-2018 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.
@@ -48,7 +48,7 @@ public final class TypeHandlerRegistry {
4848
private final TypeHandler<Object> UNKNOWN_TYPE_HANDLER = new UnknownTypeHandler(this);
4949
private final Map<Class<?>, TypeHandler<?>> ALL_TYPE_HANDLERS_MAP = new HashMap<Class<?>, TypeHandler<?>>();
5050

51-
private static final Map<JdbcType, TypeHandler<?>> NULL_TYPE_HANDLER_MAP = new HashMap<JdbcType, TypeHandler<?>>();
51+
private static final Map<JdbcType, TypeHandler<?>> NULL_TYPE_HANDLER_MAP = Collections.emptyMap();
5252

5353
private Class<? extends TypeHandler> defaultEnumTypeHandler = EnumTypeHandler.class;
5454

@@ -354,7 +354,7 @@ public <T> void register(Class<T> type, JdbcType jdbcType, TypeHandler<? extends
354354
private void register(Type javaType, JdbcType jdbcType, TypeHandler<?> handler) {
355355
if (javaType != null) {
356356
Map<JdbcType, TypeHandler<?>> map = TYPE_HANDLER_MAP.get(javaType);
357-
if (map == null) {
357+
if (map == null || map == NULL_TYPE_HANDLER_MAP) {
358358
map = new HashMap<JdbcType, TypeHandler<?>>();
359359
TYPE_HANDLER_MAP.put(javaType, map);
360360
}

src/test/java/org/apache/ibatis/type/TypeHandlerRegistryTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2017 the original author or authors.
2+
* Copyright 2009-2018 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.
@@ -206,4 +206,12 @@ public void demoTypeHandlerForSuperInterface() {
206206
assertSame(SomeInterfaceTypeHandler.class, typeHandlerRegistry.getTypeHandler(ExtendingSomeEnum.class).getClass());
207207
assertSame(SomeInterfaceTypeHandler.class, typeHandlerRegistry.getTypeHandler(ImplementingMultiInterfaceSomeEnum.class).getClass());
208208
}
209+
210+
@Test
211+
public void shouldRegisterReplaceNullMap() {
212+
class Address {}
213+
assertFalse(typeHandlerRegistry.hasTypeHandler(Address.class));
214+
typeHandlerRegistry.register(Address.class, StringTypeHandler.class);
215+
assertTrue(typeHandlerRegistry.hasTypeHandler(Address.class));
216+
}
209217
}

0 commit comments

Comments
 (0)