-
Notifications
You must be signed in to change notification settings - Fork 9
fix: ignore cases #227
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
fix: ignore cases #227
Conversation
Throwable cause = e; | ||
while (cause != null) { | ||
if (cause instanceof SocketException && "Connection reset".equals(cause.getMessage())) { | ||
if (cause instanceof SocketException && "connection reset".contains(cause.getMessage().toLowerCase())) { |
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.
Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.
This code checks the status message of the exception instead of the status itself. You could help improve backwards compatibility by checking the error code, which is less likely to change over time.
Throwable cause = e; | ||
while (cause != null) { | ||
if (cause instanceof SocketException && "Connection reset".equals(cause.getMessage())) { | ||
if (cause instanceof SocketException && "connection reset".contains(cause.getMessage().toLowerCase())) { |
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.
Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.
toLowerCase
The parameterless versions of String.toLowerCase()
and String.toUpperCase()
use the default locale of the JVM when transforming strings. This can have unintended results, including difficult-to-debug transient failures because case mapping differs based on locale.
Even if you aren’t writing code for a user experience that’s displayed to a customer, system internal code often uses case folding to normalize strings for comparison.
Not doing so can missing locale lead to errors when running on systems that are configured to use a different system locale. This can include developer desktops or build servers (not just your fleet hosts): many hours have been spent debugging errors that only occur on a specific machine due to its locale configuration.
Recommended solutions:
Always pass in a Locale
.
Language or locale-dependent processing:
Get the locale from the platform, use the language of the content, or configure it in your code and pass that to the method.
String firstName = "Ichabod";
Locale locale = // Where you obtain the locale from is platform dependent
String lowerCaseFirstName = firstName.toLowerCase(locale);
Internal processing that isn’t locale-dependent:
Example: S3 bucket name
Always specify the language/country-neutral locale Locale.ROOT
.
String imgTag = "IMG";
if ("img".equals(imgTag.toLowerCase(Locale.ROOT)) {
// do something
}
Unit Tests Coverage Report
Minimum allowed coverage is Generated by 🐒 cobertura-action against 759b80b |
Integration Tests Coverage Report
Minimum allowed coverage is Generated by 🐒 cobertura-action against 759b80b |
(cherry picked from commit 0c13acf)
Issue #, if available:
Description of changes:
Ignoring cases and white spaces
Why is this change necessary:
How was this change tested:
Any additional information or context required to review the change:
Checklist:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.