Skip to content

Commit

Permalink
Avoid a possible IndexOutOfBoundsException in MemberName.
Browse files Browse the repository at this point in the history
Ordinarily we shouldn't see an empty class name but it appears that sometimes we do: []

```
Sep 26, 2024 10:29:02 AM com.google.devtools.staticanalysis.pipeline.java.errorprone.ErrorProneFindingsJavacAnalyzer$1 handleError
WARNING: crash in Error Prone analyzer MemberName [CONTEXT ratelimit_period="5 SECONDS" analyzer="JavaStyle" ]
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
	at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:55)
	at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:52)
	at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:213)
	at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:210)
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:98)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)
	at java.base/java.lang.String.checkIndex(String.java:4881)
	at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:46)
	at java.base/java.lang.String.charAt(String.java:1582)
	at com.google.errorprone.bugpatterns.MemberName.isConformantUpperCamelName(MemberName.java:290)
	at com.google.errorprone.bugpatterns.MemberName.matchClass(MemberName.java:111)
	at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:460)
	at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:558)
	at com.google.errorprone.scanner.ErrorProneScanner.visitClass(ErrorProneScanner.java:157)
```
PiperOrigin-RevId: 679249176
  • Loading branch information
eamonnmcmanus authored and Error Prone Team committed Sep 26, 2024
1 parent 47dd2a8 commit 2b78c1f
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public final class MemberName extends BugChecker
public Description matchClass(ClassTree tree, VisitorState state) {
ClassSymbol symbol = getSymbol(tree);
String name = tree.getSimpleName().toString();
if (isConformantUpperCamelName(name)) {
if (name.isEmpty() || isConformantUpperCamelName(name)) {
// name.isEmpty() should not happen normally but could if there are errors.
return NO_MATCH;
}
String renamed = suggestedClassRename(name);
Expand Down

0 comments on commit 2b78c1f

Please sign in to comment.