-
Notifications
You must be signed in to change notification settings - Fork 744
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
BugPattern for using the default system Locale #632
Comments
A list of candidate methods can be extracted from the forbidden-apis project. I'd like to see "smart" support for |
###### _excavator_ is a bot for automating changes across repositories. Changes produced by the roomba/latest-baseline-oss check. # Release Notes ## 4.152.0 | Type | Description | Link | | ---- | ----------- | ---- | | Feature | Add DefaultLocale check<br><br>Related to https://github.com/google/error-prone/issues/632<br><br>Adds a `DefaultLocale` check that replaces uses of `String.toLowerCase()` and `String.toUpperCase()` with the overloads that take a `Locale`, using `Locale.ROOT`. | palantir/gradle-baseline#2343 | ## 4.153.0 | Type | Description | Link | | ---- | ----------- | ---- | | Fix | Set the java launcher for Checkstyle tasks, too | palantir/gradle-baseline#2351 | To enable or disable this check, please contact the maintainers of Excavator.
Fwiw, looking at which checks it provides, this might be the only reason for using forbidden-apis (unless you also want the commons.io checks), all others are either Of course, forbidden-apis works at the bytecode level so can also check bytecode generated by Groovy, Kotlin, or Scala, so can still be useful. |
We have https://errorprone.info/bugpattern/StringCaseLocaleUsage specifically for this issue in
It looks like their list is here: https://github.com/policeman-tools/forbidden-apis/blob/ce478c1ad357535518c39c5311d46ec7c0311777/src/main/resources/de/thetaphi/forbiddenapis/signatures/jdk-unsafe-1.7.txt#L52-L108
That makes sense to me, I think for something that was enabled by default in Error Prone we'd probably want it to have a lower false positive rate, and perhaps only report diagnostics if the format string is a compile-time constant that contains format specifiers that are known to be bad. |
Oh, hadn't even seen that StringCaseLocaleUsage check! (or had forgotten about it) Anyway, I'm working on that DefaultLocale check, trying to categorize the various constructors and methods into buckets (between those that could use Also fwiw, there are more than those listed in the jdk-unsafe-1.7 bundled signatures file: https://github.com/search?q=repo%3Apoliceman-tools%2Fforbidden-apis%20%22uses%20default%20locale%22&type=code |
That finally wasn't that hard 😅 PR #4487 is obviously opinionated: I finally didn't include many "display" methods (only Currency.getSymbol), I didn't include Console and explicitly excluded System.out/System.err as they're directed towards "users" and should probably use the default locale in most cases, the "smart" |
Similar to http://errorprone.info/bugpattern/DefaultCharset, it seems reasonable to have a warning of using the default system Locale, e. g. in
String.format()
.The text was updated successfully, but these errors were encountered: