Skip to content
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

Closed
waluo opened this issue Jan 17, 2018 · 2 comments
Closed
Assignees
Labels
Milestone

Comments

@waluo
Copy link

waluo commented Jan 17, 2018

MyBatis version
3.4.5

For example:

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

but

TypeHandlerRegistry tr = ...
tr.hasTypeHandler(Address.class);
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
Copy link
Member

Thank you, @waluo !

@kowalczm
Copy link

kowalczm commented Mar 5, 2018

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

pulllock pushed a commit to pulllock/mybatis-3 that referenced this issue Oct 19, 2023
…nts subsequent regiser() from working properly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants