New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't register TypeHandler after using TypeHandlerRegistry.hasTypeHandler #1177

waluo opened this Issue Jan 17, 2018 · 2 comments


None yet
3 participants

waluo commented Jan 17, 2018

MyBatis version

For example:

TypeHandlerRegistry tr = ...
tr.register(Address.class, TypeHandlers.jsonPOJO(Address.class));
tr.hasTypeHandler(Address.class);  // which return true


TypeHandlerRegistry tr = ...
tr.register(Address.class, TypeHandlers.jsonPOJO(Address.class));
tr.hasTypeHandler(Address.class); // which return false

Where the question is coming.
In org.apache.ibatis.type.TypeHandlerRegistry, NULL_TYPE_HANDLER_MAP is used for representing no handler at all.

  private Map<JdbcType, TypeHandler<?>> getJdbcHandlerMap(Type type) {
    TYPE_HANDLER_MAP.put(type, jdbcHandlerMap == null ? 
                     NULL_TYPE_HANDLER_MAP : jdbcHandlerMap); 
    return jdbcHandlerMap;

And with the following code:

  private void register(Type javaType, JdbcType jdbcType, TypeHandler<?> handler) {
    if (javaType != null) {
      Map<JdbcType, TypeHandler<?>> map = TYPE_HANDLER_MAP.get(javaType);

      // here
      if (map == null) { 
        map = new HashMap<JdbcType, TypeHandler<?>>();
        TYPE_HANDLER_MAP.put(javaType, map);
      map.put(jdbcType, handler);
    ALL_TYPE_HANDLERS_MAP.put(handler.getClass(), handler);

The code if (map == null) uses null represent an empty map instead of using NULL_TYPE_HANDLER_MAP along with, which will make all handlers cannot be registered.

@harawata harawata added the bug label Jan 17, 2018

@harawata harawata added this to the 3.4.6 milestone Jan 17, 2018

@harawata harawata self-assigned this Jan 17, 2018

@harawata harawata closed this in 9ce5260 Jan 18, 2018


This comment has been minimized.


harawata commented Jan 18, 2018

Thank you, @waluo !


This comment has been minimized.

kowalczm commented Mar 5, 2018

When we can expect release? 3.4.6 seems to be completed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment