Skip to content

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

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

Closed
fendar opened this issue Jun 3, 2016 · 6 comments
Closed
Assignees
Labels
Milestone

Comments

@fendar
Copy link

fendar commented Jun 3, 2016

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));
@fendar
Copy link
Author

fendar commented Jun 3, 2016

I want to use plugin to handle this,but it is not easy

@harawata
Copy link
Member

harawata commented Jun 3, 2016

Hi,

Have you verified that the proposed change actually fixed your problem?
I just took a quick look at the driver code, but it is doubtful that MyBatis can return the column value if the column label was null.

Regards,
Iwao

@fendar
Copy link
Author

fendar commented Jun 3, 2016

yeah,I am sure it fixed my problem.I changed the mybatis source code and mvn install in local repo.Then I debug my program, it worked well.
The jdbcType of column is not null while javaType is.

Thanks for your replied

@harawata harawata self-assigned this Jun 3, 2016
@harawata
Copy link
Member

harawata commented Jun 3, 2016

Ah, sorry, I got confused.
I'll take a look later.

@harawata harawata added the bug label Jun 3, 2016
@harawata harawata added this to the 3.4.1 milestone Jun 3, 2016
@harawata
Copy link
Member

harawata commented Jun 3, 2016

Hi @fendar ,
It should be fixed in the latest 3.4.1-SNAPSHOT.
I would appreciate if you could test it with your solution.
Thank you for the report!

@fendar
Copy link
Author

fendar commented Jun 3, 2016

Great!
I will update mybatis

pulllock pushed a commit to pulllock/mybatis-3 that referenced this issue Oct 19, 2023
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

2 participants