Skip to content

NullPointException in ResultSetHandler when java type className is null. #699

@fendar

Description

@fendar

MyBatis version

3.1.1

Database vendor and version

Kylin jdbc 1.5.1

Test case or example project

@SELECT("select a,b from table limit 1")
Map<String, Object> selectOne();

Steps to reproduce

Expected result

selectOne will return a map contain result select

Actual result

Error:
NullPointException when handling resultSet, root cause is Class.forName(null)

in FastResultSetHandler.java (DefaultResultSetHandler named in later verison)
the getTypeHandler method will throw NPE when classNames.get() return null.However, mybatis will handler the situation when can not load class(from classNames.get()).So it is ok when classNames.get() return null or can not load the class, we can ignore null.And we I ignore null,mybatis work well and return the result what I expected.
(I can not upload the image, so I paste the code)
In mybatis 3.1.1 which will throw NPE

final Class javaType = resolveClass((String)classNames.get(index)); //classNames.get() will return null in kylin-jdbc 1.5.1
  if(javaType != null && jdbcType != null) {`
       handler = typeHandlerRegistry.getTypeHandler(javaType, jdbcType);
   } else if(javaType != null) {
        handler = typeHandlerRegistry.getTypeHandler(javaType);
   } else if(jdbcType != null) { //notice:mybatis will get type handler by jdbcType if javaType is null
         handler = typeHandlerRegistry.getTypeHandler(jdbcType);
  }

so if catch the NPE,maybe it will ok,and result is what I expected, following is code

final Class javaType = classNames.get(index) == null ? null : resolveClass((String)classNames.get(index));

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions