-
Notifications
You must be signed in to change notification settings - Fork 5
fix(consensus): use Locale.ROOT for case-insensitive operations #128
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| if (!JavaVersion.current().isJava11Compatible()) { | ||
| // ErrorProne core requires JDK 11+; skip this module on JDK 8 | ||
| tasks.withType(JavaCompile).configureEach { enabled = false } | ||
| tasks.withType(Jar).configureEach { enabled = false } | ||
| } else { | ||
| dependencies { | ||
| compileOnly "com.google.errorprone:error_prone_annotations:${errorproneVersion}" | ||
| compileOnly "com.google.errorprone:error_prone_check_api:${errorproneVersion}" | ||
| compileOnly "com.google.errorprone:error_prone_core:${errorproneVersion}" | ||
| compileOnly "com.google.auto.service:auto-service:1.1.1" | ||
| annotationProcessor "com.google.auto.service:auto-service:1.1.1" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package errorprone; | ||
|
|
||
| import com.google.auto.service.AutoService; | ||
| import com.google.errorprone.BugPattern; | ||
| import com.google.errorprone.VisitorState; | ||
| import com.google.errorprone.bugpatterns.BugChecker; | ||
| import com.google.errorprone.matchers.Description; | ||
| import com.google.errorprone.util.ASTHelpers; | ||
| import com.sun.source.tree.MemberReferenceTree; | ||
| import com.sun.tools.javac.code.Symbol; | ||
| import com.sun.tools.javac.code.Type; | ||
|
Comment on lines
+10
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This checker imports Useful? React with 👍 / 👎. |
||
|
|
||
| /** | ||
| * Flags method references {@code String::toLowerCase} and {@code String::toUpperCase} | ||
| * that resolve to the no-arg overload (which uses {@code Locale.getDefault()}). | ||
| * | ||
| * <p>The built-in ErrorProne {@code StringCaseLocaleUsage} checker only catches | ||
| * direct method invocations ({@code s.toLowerCase()}), not method references | ||
| * ({@code String::toLowerCase}). This checker closes that gap. | ||
| */ | ||
| @AutoService(BugChecker.class) | ||
| @BugPattern( | ||
| name = "StringCaseLocaleUsageMethodRef", | ||
| summary = "String::toLowerCase and String::toUpperCase method references use " | ||
| + "Locale.getDefault(). Replace with a lambda that specifies Locale.ROOT, " | ||
| + "e.g. s -> s.toLowerCase(Locale.ROOT).", | ||
| severity = BugPattern.SeverityLevel.ERROR | ||
| ) | ||
| public class StringCaseLocaleUsageMethodRef extends BugChecker | ||
| implements BugChecker.MemberReferenceTreeMatcher { | ||
|
|
||
| @Override | ||
| public Description matchMemberReference(MemberReferenceTree tree, VisitorState state) { | ||
| String name = tree.getName().toString(); | ||
| if (!"toLowerCase".equals(name) && !"toUpperCase".equals(name)) { | ||
| return Description.NO_MATCH; | ||
| } | ||
| // Verify the qualifier type is java.lang.String | ||
| Type qualifierType = ((com.sun.tools.javac.tree.JCTree) tree.getQualifierExpression()) | ||
| .type; | ||
| if (qualifierType == null) { | ||
| return Description.NO_MATCH; | ||
| } | ||
| if (!state.getTypes().isSameType( | ||
| qualifierType, state.getSymtab().stringType)) { | ||
| return Description.NO_MATCH; | ||
| } | ||
| // Only flag the no-arg overload; the Locale-taking overload is safe | ||
| Symbol sym = ASTHelpers.getSymbol(tree); | ||
| if (sym instanceof Symbol.MethodSymbol | ||
| && ((Symbol.MethodSymbol) sym).getParameters().isEmpty()) { | ||
| return describeMatch(tree); | ||
| } | ||
| return Description.NO_MATCH; | ||
| } | ||
| } | ||
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.
Suggestion:
dbEngineis used withtoUpperCase(Locale.ROOT)without a null check, so an unset storage engine value will throw aNullPointerExceptionbefore the fallback error branch is reached. Guard against null first, then normalize and compare. [null pointer]Severity Level: Major⚠️
Steps of Reproduction ✅
Fix in Cursor | Fix in VSCode Claude
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖