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

CharacterTypeHandler#getNullableResult() throws StringIndexOutOfBoundsException #2368

Merged
merged 3 commits into from
Dec 10, 2021

Conversation

mrsun002
Copy link
Contributor

this is a basic error, the condition statement miss the [String !=""] condition in if(...);
in this case, i execute the select sql statement, and the resultType include a property -- Character type, when the DataBase return a "", Mybatis will throw a Exception: index out of range, becasue the array's length is 0 in the statement -- "return columnValue.charAt(0);"

first,this is a basic error, the condition statement miss the "" condition in if(...);
in this case, i execute the select sql statement, and the resultType include a property -- Character type, when the DataBase return a "", Mybatis will throw a Exception: index out of range, becasue the array's length is 0 in the statement -- "return columnValue.charAt(0);"
Copy link
Member

@harawata harawata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

columnValue != "" is not the right comparison.
Please use columnValue.isEmpty().

@mrsun002
Copy link
Contributor Author

columnValue != "" is not the right comparison. Please use columnValue.isEmpty().

Yes, You are right. If the columnValue = new String(), then ( columnValue == "" ) will return false,
can use { !columnValue.isEmpty() } or { s.equals("")) } to replace it ;

@mrsun002 mrsun002 requested a review from harawata December 10, 2021 11:57
Copy link
Contributor Author

@mrsun002 mrsun002 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modify the ( columnValue != "" } to { !columnValue.isEmpty() }

@coveralls
Copy link

Coverage Status

Coverage increased (+0.009%) to 87.256% when pulling 71bc47e on mrsun002:mrsun002-fixTheCharacterTypeHandler into 0133e37 on mybatis:master.

@harawata harawata self-assigned this Dec 10, 2021
@harawata harawata added the bug label Dec 10, 2021
@harawata harawata added this to the 3.5.8 milestone Dec 10, 2021
@harawata harawata changed the title Update CharacterTypeHandler.java CharacterTypeHandler#getNullableResult() throws StringIndexOutOfBoundsException Dec 10, 2021
@harawata harawata merged commit b454d47 into mybatis:master Dec 10, 2021
@harawata
Copy link
Member

Thank you, @mrsun002 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants