-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Include actual cause's message in various parsing exception messages #32636
Conversation
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.
@remeio thanks for the PR. There is indeed a bit of an inconsistency here, but we don't think the fix you proposed is the best approach. With the current approach, we intentionally present the erroneous timeoutString
in the message. It's just that the second half of the message that becomes misleading in the -2
case.
I would suggest that instead of changing the type of exception caught, you change the exception message to replace \" - cannot parse into int
with \"; " + ex
. That way the message will consistently reflect the actual underlying reason.
Thanks, I agree with you. |
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.
yeah, looking better 👍
I was made aware that there are 3 similar cases in ScheduledAnnotationBeanPostProcessor
as well (look for "- cannot parse into"). Would you like to also fix these with a similar change as part of this PR?
@@ -206,7 +206,7 @@ public void resolveAttributeStrings(@Nullable StringValueResolver resolver) { | |||
} | |||
catch (RuntimeException ex) { | |||
throw new IllegalArgumentException( | |||
"Invalid timeoutString value \"" + timeoutString + "\" - cannot parse into int"); | |||
"Invalid timeoutString value \"" + timeoutString + "\": " + ex); |
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.
let's use ;
as a separator since :
is already part of Throwable::toString
"Invalid timeoutString value \"" + timeoutString + "\": " + ex); | |
"Invalid timeoutString value \"" + timeoutString + "\"; " + ex); |
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.
Ok, I will fix these cases together
(marking as |
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.
thanks for the PR @remeio 👍
When
timeoutString
is"-2"
,DefaultTransactionDefinition#setTimeout
method will throwIllegalArgumentException
(it extendsRuntimeException
), we will get the error message:Invalid timeoutString value "-2" - cannot parse into int
.But actually
"-2"
can parse into int.In other words, the error message
cannot parse into int
is just right forInteger#parseInt
, so I changeRuntimeException
toNumberFormatException
. So:timeoutString
is"1"
, just ok.timeoutString
is"-2"
, we will get:Timeout must be a positive integer or TIMEOUT_DEFAULT
.timeoutString
is"foo"
, we will get:Invalid timeoutString value "foo" - cannot parse into int
.