Skip to content

Commit

Permalink
Subsume StackTraceElementGetClass into DoNotCall.
Browse files Browse the repository at this point in the history
This loses the intricate refactorings provided by the former, but standardises on one check.

PiperOrigin-RevId: 421787835
  • Loading branch information
graememorgan authored and Error Prone Team committed Jan 14, 2022
1 parent 9889e7a commit e1d3844
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 235 deletions.
Expand Up @@ -130,6 +130,11 @@ public class DoNotCallChecker extends BugChecker
.onExactClass("java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock")
.named("newCondition"),
"ReadLocks do not support conditions.")
.put(
instanceMethod().onExactClass("java.lang.StackTraceElement").named("getClass"),
"Calling getClass on StackTraceElement returns the Class object for"
+ " StackTraceElement, you probably meant to retrieve the class containing the"
+ " execution point represented by this stack trace element using getClassName")
.buildOrThrow();

static final String DO_NOT_CALL = "com.google.errorprone.annotations.DoNotCall";
Expand Down

This file was deleted.

Expand Up @@ -307,7 +307,6 @@
import com.google.errorprone.bugpatterns.ShortCircuitBoolean;
import com.google.errorprone.bugpatterns.ShouldHaveEvenArgs;
import com.google.errorprone.bugpatterns.SizeGreaterThanOrEqualsZero;
import com.google.errorprone.bugpatterns.StackTraceElementGetClass;
import com.google.errorprone.bugpatterns.StaticAssignmentInConstructor;
import com.google.errorprone.bugpatterns.StaticMockMember;
import com.google.errorprone.bugpatterns.StaticQualifiedUsingExpression;
Expand Down Expand Up @@ -726,7 +725,6 @@ public static ScannerSupplier errorChecks() {
SelfEquals.class,
ShouldHaveEvenArgs.class,
SizeGreaterThanOrEqualsZero.class,
StackTraceElementGetClass.class,
StreamToString.class,
StringBuilderInitWithChar.class,
SubstringOfZero.class,
Expand Down
Expand Up @@ -552,4 +552,22 @@ public void typeArgs_dontCrash() {
"}")
.doTest();
}

@Test
public void positive_getSimpleName_refactoredToGetClassName() {
testHelper
.addSourceLines(
"Test.java",
"class Test{",
" void f() {",
" try {",
" throw new Exception();",
" } catch (Exception ex) {",
" // BUG: Diagnostic contains: getClassName",
" ex.getStackTrace()[0].getClass().getSimpleName();",
" }",
" }",
"}")
.doTest();
}
}

This file was deleted.

7 changes: 0 additions & 7 deletions docs/bugpattern/StackTraceElementGetClass.md

This file was deleted.

0 comments on commit e1d3844

Please sign in to comment.