Update UnsafeLocaleUsage with detection for Locale.of#5279
Conversation
Stephan202
left a comment
There was a problem hiding this comment.
Just something I noticed on a quick skim.
Co-authored-by: Stephan Schroevers <stephan202@gmail.com>
| + " (which takes in an IETF BCP 47-formatted string) or a Locale.Builder" | ||
| + " (which throws exceptions when the input is not well-formed).\n" | ||
| + "Please read the Error Prone documentation page for UnsafeLocaleUsage for" | ||
| + " more information."); |
There was a problem hiding this comment.
The generated diagnostics automatically include the link to the full 'explanation', so writing this out here isn't necessary
| Description.Builder descriptionBuilder = | ||
| buildDescription(tree) | ||
| .setMessage( | ||
| "Avoid using Locale.of static methods (which do not check their arguments for" |
There was a problem hiding this comment.
By default, the message is the BugPattern.summary. Is there information here that applies to all findings that could go in the summary instead?
If you want to customize this to mention e.g. Locale.of vs. Locale constructors, WDYT about refactoring and using a format string to share the text that's the same for both?
There was a problem hiding this comment.
Between constructors and Locale.of there is a lot of sharing (they are basically the same).
I refactored the messages to share, as suggested.
toString throws a wrench in reusing much in the summary.
But while reviewing it I discovered that java.util.Locale is not a library :-), and I fixed that.
| Description.Builder descriptionBuilder = | ||
| buildDescription(tree) | ||
| .setMessage( | ||
| "Avoid using Locale.of static methods (which do not check their arguments for" |
There was a problem hiding this comment.
Between constructors and Locale.of there is a lot of sharing (they are basically the same).
I refactored the messages to share, as suggested.
toString throws a wrench in reusing much in the summary.
But while reviewing it I discovered that java.util.Locale is not a library :-), and I fixed that.
| + " (which takes in an IETF BCP 47-formatted string) or a Locale.Builder" | ||
| + " (which throws exceptions when the input is not well-formed).\n" | ||
| + "Please read the Error Prone documentation page for UnsafeLocaleUsage for" | ||
| + " more information."); |
Fix for #5278