-
Notifications
You must be signed in to change notification settings - Fork 26.5k
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
[Dubbo-3069] Fix NumberFormatException for input string "" #3076
Conversation
Hi, @zhaixiaoxiang
Return '\0' may be confusing. How about put the |
duplicate: #3075 |
Yes, ClassHelper.convertPrimitive() is only used in one place, and '\0' is not used, so I remove '\0'.
|
@@ -343,6 +343,20 @@ public static boolean isBlank(String str) { | |||
return isEmpty(str); | |||
} | |||
|
|||
public static boolean isRealBlank(CharSequence cs) { | |||
int strLen; | |||
if (cs != null && (strLen = cs.length()) != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be replaced by 'StringUtils.isNotEmpty(cs)'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plz ignore my comment.
@@ -343,6 +343,20 @@ public static boolean isBlank(String str) { | |||
return isEmpty(str); | |||
} | |||
|
|||
public static boolean isRealBlank(CharSequence cs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be replace is
public static boolean isRealBlank(CharSequence cs) {
int strLen;
if (cs != null && (strLen = cs.length()) != 0) {
for (int i = 0; i < strLen; ++i) {
if (!Character.isWhitespace(cs.charAt(i))) {
return false;
}
}
}
return true;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, what can be replaced by what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
existing isRealBlank can be change with given one. It is not exact replacement, I have paste the whole code of isRealBlank with modified one so that you don't have to spend time modifying line by line. In the modified one I have remove the extra return statement because the return at the end of method is good enough for the purpose.
Codecov Report
@@ Coverage Diff @@
## master #3076 +/- ##
=========================================
Coverage ? 63.56%
Complexity ? 75
=========================================
Files ? 653
Lines ? 28228
Branches ? 4807
=========================================
Hits ? 17943
Misses ? 8010
Partials ? 2275
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, there are too many unrelated changes.
Please focus on one single improvement at a time.
} else if (type == boolean.class || type == Boolean.class) { | ||
return Boolean.valueOf(value); | ||
} else if (StringUtils.isRealBlank(value)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
I think we don't need to call isRealBlank
, because there is too much to check. If we really want to check, we need to make sure the input value
is numeric. I have left comment on #3093
return false; | ||
} | ||
} | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this return (after for loop)is not requires and remove the else and keep just return true;
Fix #3069
What is the purpose of the change
Fix NumberFormatException for input string "" or " " or null in convertPrimitive(Class<?> type, String value)
Brief changelog
Update files:
ClassHelper
StringUtils
ClassHelperTest
StringUtilsTest
Verifying this change
Follow this checklist to help us incorporate your contribution quickly and easily:
[Dubbo-XXX] Fix UnknownException when host config not exist #XXX
. Each commit in the pull request should have a meaningful subject line and body.mvn clean install -DskipTests
&mvn clean test-compile failsafe:integration-test
to make sure unit-test and integration-test pass.