From 3141d98f55e114fd22909eff630109809a7889fb Mon Sep 17 00:00:00 2001 From: Chaoren Lin Date: Tue, 12 Nov 2024 15:57:47 -0800 Subject: [PATCH] Simplify `AbstractMustBeClosedChecker` with Java 21 features. PiperOrigin-RevId: 695900731 --- .../AbstractMustBeClosedChecker.java | 179 ++++++++---------- .../bugpatterns/ArrayEqualsTest.java | 12 +- .../bugpatterns/ArrayHashCodeTest.java | 9 +- .../bugpatterns/ArrayToStringTest.java | 18 +- .../bugpatterns/AssertFalseTest.java | 6 +- .../AsyncFunctionReturnsNullTest.java | 6 +- .../bugpatterns/BadComparableTest.java | 6 +- .../errorprone/bugpatterns/BadImportTest.java | 12 +- .../bugpatterns/BadShiftAmountTest.java | 6 +- .../bugpatterns/BanClassLoaderTest.java | 6 +- .../errorprone/bugpatterns/BanJNDITest.java | 9 +- .../ByteBufferBackingArrayTest.java | 6 +- .../bugpatterns/CannotMockFinalClassTest.java | 9 +- .../ChainedAssertionLosesContextTest.java | 6 +- ...ainingConstructorIgnoresParameterTest.java | 6 +- .../bugpatterns/CheckReturnValueTest.java | 6 +- .../bugpatterns/ClassCanBeStaticTest.java | 12 +- .../CollectionToArraySafeParameterTest.java | 6 +- .../CollectorShouldNotUseStateTest.java | 6 +- .../ComparableAndComparatorTest.java | 6 +- .../bugpatterns/ComparableTypeTest.java | 6 +- .../ComparisonContractViolatedTest.java | 6 +- .../bugpatterns/ComparisonOutOfRangeTest.java | 6 +- .../bugpatterns/DeadExceptionTest.java | 9 +- .../errorprone/bugpatterns/DepAnnTest.java | 12 +- .../bugpatterns/EmptyCatchTest.java | 6 +- .../bugpatterns/EmptyIfStatementTest.java | 6 +- .../bugpatterns/EqualsHashCodeTest.java | 6 +- .../EqualsIncompatibleTypeTest.java | 9 +- .../errorprone/bugpatterns/EqualsNaNTest.java | 6 +- .../bugpatterns/EqualsReferenceTest.java | 6 +- ...neousThreadPoolConstructorCheckerTest.java | 6 +- .../bugpatterns/FallThroughTest.java | 6 +- .../errorprone/bugpatterns/FinallyTest.java | 12 +- ...oatingPointAssertionWithinEpsilonTest.java | 12 +- .../FunctionalInterfaceMethodChangedTest.java | 6 +- .../FutureReturnValueIgnoredTest.java | 6 +- ...resGetCheckedIllegalExceptionTypeTest.java | 6 +- ...ualsShouldNotBeUsedInEqualsMethodTest.java | 6 +- .../bugpatterns/GetClassOnClassTest.java | 6 +- .../bugpatterns/HidingFieldTest.java | 9 +- .../ImplementAssertionWithChainingTest.java | 6 +- .../InconsistentCapitalizationTest.java | 3 +- .../IncrementInForLoopAndHeaderTest.java | 6 +- .../bugpatterns/InsecureCipherModeTest.java | 6 +- .../InstanceOfAndCastMatchWrongTypeTest.java | 6 +- .../bugpatterns/InvalidPatternSyntaxTest.java | 6 +- .../bugpatterns/IterableAndIteratorTest.java | 6 +- .../bugpatterns/JUnit3TestNotRunTest.java | 21 +- .../bugpatterns/JUnit4SetUpNotRunTest.java | 12 +- .../bugpatterns/JUnit4TearDownNotRunTest.java | 12 +- .../bugpatterns/JUnit4TestNotRunTest.java | 24 ++- .../bugpatterns/JUnitAssertSameCheckTest.java | 6 +- .../JUnitParameterMethodNotFoundTest.java | 15 +- .../LambdaFunctionalInterfaceTest.java | 6 +- .../bugpatterns/LiteEnumValueOfTest.java | 6 +- .../LockOnNonEnclosingClassLiteralTest.java | 6 +- .../LongLiteralLowerCaseSuffixTest.java | 12 +- .../MisleadingEscapedSpaceTest.java | 24 ++- .../bugpatterns/MissingFailTest.java | 15 +- .../bugpatterns/MisusedWeekYearTest.java | 9 +- ...ModifyCollectionInEnhancedForLoopTest.java | 6 +- .../ModifySourceCollectionInStreamTest.java | 6 +- .../ModifyingCollectionWithItselfTest.java | 6 +- ...MultipleParallelOrSequentialCallsTest.java | 12 +- ...ultipleUnaryOperatorsInMethodCallTest.java | 6 +- .../NestedInstanceOfConditionsTest.java | 6 +- .../bugpatterns/NoAllocationCheckerTest.java | 6 +- .../NonAtomicVolatileUpdateTest.java | 6 +- .../bugpatterns/NonRuntimeAnnotationTest.java | 6 +- .../bugpatterns/ObjectToStringTest.java | 6 +- .../bugpatterns/OptionalNotPresentTest.java | 6 +- .../OverrideThrowableToStringTest.java | 12 +- .../errorprone/bugpatterns/OverridesTest.java | 24 ++- .../PreconditionsInvalidPlaceholderTest.java | 6 +- ...imitiveArrayPassedToVarargsMethodTest.java | 6 +- ...rivateSecurityContractProtoAccessTest.java | 6 +- .../ProtocolBufferOrdinalTest.java | 6 +- .../bugpatterns/RestrictedApiCheckerTest.java | 6 +- ...eOperationExceptionAsLinkageErrorTest.java | 6 +- .../bugpatterns/ReturnValueIgnoredTest.java | 6 +- .../bugpatterns/RxReturnValueIgnoredTest.java | 6 +- .../bugpatterns/SelfAssertionTest.java | 6 +- .../bugpatterns/SelfAssignmentTest.java | 9 +- .../bugpatterns/SelfComparisonTest.java | 6 +- .../bugpatterns/SelfEqualsTest.java | 12 +- .../bugpatterns/ShouldHaveEvenArgsTest.java | 12 +- .../SizeGreaterThanOrEqualsZeroTest.java | 6 +- .../StaticQualifiedUsingExpressionTest.java | 9 +- .../StringBuilderInitWithCharTest.java | 6 +- .../bugpatterns/StringSplitterTest.java | 6 +- .../SuppressWarningsDeprecatedTest.java | 6 +- .../bugpatterns/SwigMemoryLeakTest.java | 6 +- .../bugpatterns/ThreadJoinLoopTest.java | 12 +- .../ThrowIfUncheckedKnownCheckedTest.java | 6 +- .../ThrowsUncheckedExceptionTest.java | 6 +- .../bugpatterns/TreeToStringTest.java | 6 +- .../bugpatterns/TruthAssertExpectedTest.java | 6 +- .../bugpatterns/TruthConstantAssertsTest.java | 6 +- .../bugpatterns/TryFailThrowableTest.java | 6 +- .../bugpatterns/URLEqualsHashCodeTest.java | 6 +- .../bugpatterns/UngroupedOverloadsTest.java | 36 ++-- .../UnnecessaryBoxedAssignmentTest.java | 6 +- .../UnnecessaryBoxedVariableTest.java | 6 +- .../UnnecessaryLongToIntConversionTest.java | 6 +- .../UnsafeReflectiveConstructionCastTest.java | 3 +- .../bugpatterns/WaitNotInLoopTest.java | 6 +- ...BinderIdentityRestoredDangerouslyTest.java | 3 +- .../android/FragmentInjectionTest.java | 3 +- .../android/FragmentNotInstantiableTest.java | 30 ++- .../android/HardCodedSdCardPathTest.java | 6 +- .../android/IsLoggableTagLengthTest.java | 3 +- .../android/MislabeledAndroidStringTest.java | 3 +- .../RectIntersectReturnValueIgnoredTest.java | 9 +- .../WakelockReleasedDangerouslyTest.java | 6 +- .../CollectionIncompatibleTypeTest.java | 12 +- .../IncompatibleArgumentTypeTest.java | 12 +- .../FloggerRedundantIsEnabledTest.java | 12 +- ...stedInjectAndInjectOnConstructorsTest.java | 6 +- ...dInjectAndInjectOnSameConstructorTest.java | 6 +- .../inject/AutoFactoryAtInjectTest.java | 6 +- .../inject/CloseableProvidesTest.java | 6 +- .../InjectOnMemberAndConstructorTest.java | 3 +- .../InjectedConstructorAnnotationsTest.java | 6 +- ...validTargetingOnScopingAnnotationTest.java | 6 +- .../JavaxInjectOnAbstractMethodTest.java | 6 +- .../inject/JavaxInjectOnFinalFieldTest.java | 6 +- .../inject/MissingRuntimeRetentionTest.java | 6 +- .../MoreThanOneInjectableConstructorTest.java | 6 +- .../inject/MoreThanOneQualifierTest.java | 6 +- ...MoreThanOneScopeAnnotationOnClassTest.java | 6 +- ...appingQualifierAndScopeAnnotationTest.java | 6 +- .../inject/QualifierWithTypeUseTest.java | 6 +- ...otationOnInterfaceOrAbstractClassTest.java | 6 +- .../AndroidInjectionBeforeSuperTest.java | 33 ++-- .../guice/AssistedInjectScopingTest.java | 6 +- .../inject/guice/AssistedParametersTest.java | 6 +- .../BindingToUnqualifiedCommonTypeTest.java | 6 +- .../inject/guice/InjectOnFinalFieldTest.java | 6 +- .../OverridesGuiceInjectableMethodTest.java | 6 +- .../OverridesJavaxInjectableMethodTest.java | 6 +- .../ProvidesMethodOutsideOfModuleTest.java | 6 +- .../nullness/EqualsBrokenForNullTest.java | 6 +- .../nullness/NullablePrimitiveTest.java | 6 +- .../nullness/UnnecessaryCheckNotNullTest.java | 12 +- .../nullness/UnsafeWildcardTest.java | 3 +- .../InconsistentOverloadsTest.java | 24 ++- .../time/TimeUnitMismatchTest.java | 6 +- .../NullnessPropagationTest.java | 24 ++- 149 files changed, 892 insertions(+), 505 deletions(-) diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/AbstractMustBeClosedChecker.java b/core/src/main/java/com/google/errorprone/bugpatterns/AbstractMustBeClosedChecker.java index fc3c4585ee0..791437a0e19 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/AbstractMustBeClosedChecker.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/AbstractMustBeClosedChecker.java @@ -47,6 +47,7 @@ import com.google.errorprone.matchers.Matcher; import com.google.errorprone.matchers.UnusedReturnValueMatcher; import com.google.errorprone.util.ASTHelpers; +import com.sun.source.tree.AssignmentTree; import com.sun.source.tree.BlockTree; import com.sun.source.tree.ConditionalExpressionTree; import com.sun.source.tree.ExpressionStatementTree; @@ -56,6 +57,7 @@ import com.sun.source.tree.MethodInvocationTree; import com.sun.source.tree.MethodTree; import com.sun.source.tree.NewClassTree; +import com.sun.source.tree.ReturnTree; import com.sun.source.tree.StatementTree; import com.sun.source.tree.Tree; import com.sun.source.tree.TryTree; @@ -111,17 +113,14 @@ String uniquifyName(String basename) { * @param tree must be either MethodInvocationTree or NewClassTree */ String suggestName(ExpressionTree tree) { - String symbolName; - switch (tree.getKind()) { - case NEW_CLASS: - symbolName = getSymbol(((NewClassTree) tree).getIdentifier()).getSimpleName().toString(); - break; - case METHOD_INVOCATION: - symbolName = getReturnType(tree).asElement().getSimpleName().toString(); - break; - default: - throw new AssertionError(tree.getKind()); - } + String symbolName = + switch (tree) { + case NewClassTree newClassTree -> + getSymbol(newClassTree.getIdentifier()).getSimpleName().toString(); + case MethodInvocationTree methodInvocationTree -> + getReturnType(methodInvocationTree).asElement().getSimpleName().toString(); + default -> throw new AssertionError(tree.getKind()); + }; return uniquifyName(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, symbolName)); } } @@ -255,80 +254,72 @@ private Optional checkClosed( while (true) { TreePath prev = path; path = path.getParentPath(); - switch (path.getLeaf().getKind()) { - case RETURN: - if (callerMethodTree != null) { - // The invocation occurs within a return statement of a method, instead of a lambda - // expression or anonymous class. - if (HAS_MUST_BE_CLOSED_ANNOTATION.matches(callerMethodTree, state)) { - // Ignore invocations of annotated methods and constructors that occur in the return - // statement of an annotated caller method, since invocations of the caller are - // enforced. - return Optional.empty(); - } - // The caller method is not annotated, so the closing of the returned resource is not - // enforced. Suggest fixing this by annotating the caller method. - return Change.of( - SuggestedFix.builder() - .prefixWith(callerMethodTree, "@MustBeClosed\n") - .addImport(MustBeClosed.class.getCanonicalName()) - .build()); + switch (path.getLeaf()) { + case ReturnTree unused when callerMethodTree != null -> { + // The invocation occurs within a return statement of a method, instead of a lambda + // expression or anonymous class. + if (HAS_MUST_BE_CLOSED_ANNOTATION.matches(callerMethodTree, state)) { + // Ignore invocations of annotated methods and constructors that occur in the return + // statement of an annotated caller method, since invocations of the caller are + // enforced. + return Optional.empty(); } + // The caller method is not annotated, so the closing of the returned resource is not + // enforced. Suggest fixing this by annotating the caller method. + return Change.of( + SuggestedFix.builder() + .prefixWith(callerMethodTree, "@MustBeClosed\n") + .addImport(MustBeClosed.class.getCanonicalName()) + .build()); + } + case ReturnTree unused -> { // If enclosingMethod returned null, we must be returning from a statement lambda. return handleTailPositionInLambda(state); - case LAMBDA_EXPRESSION: + } + case LambdaExpressionTree unused -> { // The method invocation is the body of an expression lambda. return handleTailPositionInLambda(state); - case CONDITIONAL_EXPRESSION: - ConditionalExpressionTree conditionalExpressionTree = - (ConditionalExpressionTree) path.getLeaf(); - if (conditionalExpressionTree.getTrueExpression().equals(prev.getLeaf()) - || conditionalExpressionTree.getFalseExpression().equals(prev.getLeaf())) { + } + case ConditionalExpressionTree conditionalExpressionTree + when conditionalExpressionTree.getTrueExpression().equals(prev.getLeaf()) + || conditionalExpressionTree.getFalseExpression().equals(prev.getLeaf()) -> { + continue OUTER; + } + case MemberSelectTree memberSelectTree + when memberSelectTree.getExpression().equals(prev.getLeaf()) -> { + Type type = getType(memberSelectTree); + Symbol sym = getSymbol(memberSelectTree); + Type streamType = state.getTypeFromString(Stream.class.getName()); + if (isSubtype(sym.enclClass().asType(), streamType, state) + && isSameType(type.getReturnType(), streamType, state)) { + // skip enclosing method invocation + path = path.getParentPath(); continue OUTER; } - break; - case MEMBER_SELECT: - MemberSelectTree memberSelectTree = (MemberSelectTree) path.getLeaf(); - if (memberSelectTree.getExpression().equals(prev.getLeaf())) { - Type type = getType(memberSelectTree); - Symbol sym = getSymbol(memberSelectTree); - Type streamType = state.getTypeFromString(Stream.class.getName()); - if (isSubtype(sym.enclClass().asType(), streamType, state) - && isSameType(type.getReturnType(), streamType, state)) { - // skip enclosing method invocation - path = path.getParentPath(); - continue OUTER; - } - } - break; - case NEW_CLASS: - NewClassTree newClassTree = (NewClassTree) path.getLeaf(); - if (isClosingDecorator(newClassTree, prev.getLeaf(), state)) { - if (HAS_MUST_BE_CLOSED_ANNOTATION.matches(newClassTree, state)) { - // if the decorator is also annotated then it would already be enforced - return Optional.empty(); - } - // otherwise, enforce that the decorator must be closed - continue OUTER; + } + case NewClassTree newClassTree + when isClosingDecorator(newClassTree, prev.getLeaf(), state) -> { + if (HAS_MUST_BE_CLOSED_ANNOTATION.matches(newClassTree, state)) { + // if the decorator is also annotated then it would already be enforced + return Optional.empty(); } - break; - case VARIABLE: - Symbol sym = getSymbol(path.getLeaf()); - if (sym instanceof VarSymbol) { - VarSymbol var = (VarSymbol) sym; - if (var.getKind() == ElementKind.RESOURCE_VARIABLE - || isClosedInFinallyClause(var, path, state) - || ASTHelpers.variableIsStaticFinal(var)) { - return Optional.empty(); - } + // otherwise, enforce that the decorator must be closed + continue OUTER; + } + case VariableTree variableTree -> { + VarSymbol var = getSymbol(variableTree); + if (var.getKind() == ElementKind.RESOURCE_VARIABLE + || isClosedInFinallyClause(var, path, state) + || ASTHelpers.variableIsStaticFinal(var)) { + return Optional.empty(); } - break; - case ASSIGNMENT: + } + case AssignmentTree unused -> { // We shouldn't suggest a try/finally fix when we know the variable is going to be saved // for later. return findingWithNoFix(); - default: - break; + } + default -> {} } // The constructor or method invocation does not occur within the resource variable // initializer of a try-with-resources statement. @@ -368,8 +359,7 @@ private static Optional findingWithNoFix() { private static @Nullable MethodTree enclosingMethod(VisitorState state) { for (Tree node : state.getPath().getParentPath()) { switch (node.getKind()) { - case LAMBDA_EXPRESSION: - case NEW_CLASS: + case LAMBDA_EXPRESSION, NEW_CLASS: return null; case METHOD: return (MethodTree) node; @@ -384,21 +374,15 @@ private static boolean isClosedInFinallyClause(VarSymbol var, TreePath path, Vis if (!isConsideredFinal(var)) { return false; } - Tree parent = path.getParentPath().getLeaf(); - if (parent.getKind() != Tree.Kind.BLOCK) { + if (!(path.getParentPath().getLeaf() instanceof BlockTree block)) { return false; } - BlockTree block = (BlockTree) parent; int idx = block.getStatements().indexOf(path.getLeaf()); if (idx == -1 || idx == block.getStatements().size() - 1) { return false; } StatementTree next = block.getStatements().get(idx + 1); - if (!(next instanceof TryTree)) { - return false; - } - TryTree tryTree = (TryTree) next; - if (tryTree.getFinallyBlock() == null) { + if (!(next instanceof TryTree tryTree) || tryTree.getFinallyBlock() == null) { return false; } boolean[] closed = {false}; @@ -421,23 +405,20 @@ public Void visitMethodInvocation(MethodInvocationTree tree, Void unused) { private static Optional chooseFixType( ExpressionTree tree, VisitorState state, NameSuggester suggester) { - TreePath path = state.getPath(); - Tree parent = path.getParentPath().getLeaf(); - if (parent instanceof VariableTree) { - return wrapTryFinallyAroundVariableScope((VariableTree) parent, state); - } - StatementTree stmt = state.findEnclosing(StatementTree.class); - if (stmt == null) { - return Optional.empty(); - } - if (!(stmt instanceof VariableTree)) { - return introduceSingleStatementTry(tree, stmt, state, suggester); + if (state.getPath().getParentPath().getLeaf() instanceof VariableTree parent) { + return wrapTryFinallyAroundVariableScope(parent, state); } - VarSymbol varSym = getSymbol((VariableTree) stmt); - if (varSym.getKind() == ElementKind.RESOURCE_VARIABLE) { - return extractToResourceInCurrentTry(tree, stmt, state, suggester); - } - return splitVariableDeclarationAroundTry(tree, (VariableTree) stmt, state, suggester); + return switch (state.findEnclosing(StatementTree.class)) { + case null -> Optional.empty(); + case VariableTree stmt -> { + VarSymbol varSym = getSymbol(stmt); + if (varSym.getKind() == ElementKind.RESOURCE_VARIABLE) { + yield extractToResourceInCurrentTry(tree, stmt, state, suggester); + } + yield splitVariableDeclarationAroundTry(tree, stmt, state, suggester); + } + case StatementTree stmt -> introduceSingleStatementTry(tree, stmt, state, suggester); + }; } private static Optional introduceSingleStatementTry( diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ArrayEqualsTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ArrayEqualsTest.java index 1b81fd1f0a6..8032b99b2c3 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ArrayEqualsTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ArrayEqualsTest.java @@ -118,7 +118,8 @@ public void bothMethodCalls() { System.out.println("arrays are not equal!"); } } - }""") + }\ + """) .doTest(); } @@ -162,7 +163,8 @@ public void objectArray() { System.out.println("arrays are not equal!"); } } - }""") + }\ + """) .doTest(); } @@ -230,7 +232,8 @@ public void secondArray() { System.out.println("Objects are not equal!"); } } - }""") + }\ + """) .doTest(); } @@ -282,7 +285,8 @@ public void secondArray() { System.out.println("arrays are not equal!"); } } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ArrayHashCodeTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ArrayHashCodeTest.java index f57d4f24def..4976c6e15f7 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ArrayHashCodeTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ArrayHashCodeTest.java @@ -104,7 +104,8 @@ public void varargsHashCodeOnMoreThanOneArg() { // Arrays.deepHashCode(multidimensionalStringArray)) hashCode = Objects.hashCode(obj1, obj2, multidimensionalStringArray); } -}""") +}\ +""") .doTest(); } @@ -147,7 +148,8 @@ public void varagsHashCodeOnObjectOrStringArray() { hashCode = Objects.hashCode(objArray); hashCode = Objects.hashCode((Object[]) stringArray); } - }""") + }\ + """) .doTest(); } @@ -193,7 +195,8 @@ public void varagsHashCodeOnObjectOrStringArray() { hashCode = Objects.hash(objArray); hashCode = Objects.hash((Object[]) stringArray); } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ArrayToStringTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ArrayToStringTest.java index 6e46908d040..2f151036060 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ArrayToStringTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ArrayToStringTest.java @@ -102,7 +102,8 @@ public void arrayOfArrays() { // BUG: Diagnostic contains: Arrays.deepToString(a) System.out.println(a); } - }""") + }\ + """) .doTest(); } @@ -129,7 +130,8 @@ public void objectEquals() { System.out.println("string is not empty!"); } } - }""") + }\ + """) .doTest(); } @@ -305,7 +307,8 @@ public void stringVariableAddsArrayAndAssigns() { // BUG: Diagnostic contains: += Arrays.toString(a) b += a; } - }""") + }\ + """) .doTest(); } @@ -332,7 +335,8 @@ public void concatenateCompoundAssign_int() { String b = " a string "; b += a; } - }""") + }\ + """) .doTest(); } @@ -362,7 +366,8 @@ public void stringLiteralRightOperandIsArray() { // BUG: Diagnostic contains: + Arrays.toString(a) String b = "a string" + a; } - }""") + }\ + """) .doTest(); } @@ -388,7 +393,8 @@ public void notArray_refactored() { String b = " a string"; String c = a + b; } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/AssertFalseTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/AssertFalseTest.java index 10883b78bbb..76e2a97c2f6 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/AssertFalseTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/AssertFalseTest.java @@ -50,7 +50,8 @@ public void assertTrue() { public void assertFalseFromCondition() { assert 0 == 1; } - }""") + }\ + """) .doTest(); } @@ -70,7 +71,8 @@ public void assertFalse() { // BUG: Diagnostic contains: throw new AssertionError() assert false; } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/AsyncFunctionReturnsNullTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/AsyncFunctionReturnsNullTest.java index d04d9904eff..0abe157bd5b 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/AsyncFunctionReturnsNullTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/AsyncFunctionReturnsNullTest.java @@ -69,7 +69,8 @@ public ListenableFuture apply(Object input) throws Exception { return immediateFuture(input.toString()); } } - }""") + }\ + """) .doTest(); } @@ -139,7 +140,8 @@ public ListenableFuture apply(String input) throws Exception { interface MyNonAsyncFunction { ListenableFuture apply(@Nullable I input) throws Exception; } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/BadComparableTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/BadComparableTest.java index 63594f2716f..fae1062fcf3 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/BadComparableTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/BadComparableTest.java @@ -85,7 +85,8 @@ public int compare(File lhs, File rhs) { return (int) (rhs.lastModified() - lhs.lastModified()); } }; -}""") +}\ +""") .doTest(); } @@ -231,7 +232,8 @@ public char compare(byte n1, byte n2) { return (char) (n1 - n2); } }; - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/BadImportTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/BadImportTest.java index cfa2c8ea462..f8853c247fb 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/BadImportTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/BadImportTest.java @@ -243,7 +243,8 @@ Builder returnRaw() { void classLiteral() { System.out.println(Builder.class); } -}""") +}\ +""") .doTest(); } @@ -354,7 +355,8 @@ void useNestedBuilder() { new Builder(); } } - }""") + }\ + """) .doTest(); } @@ -438,7 +440,8 @@ Builder returnRaw() { void classLiteral() { System.out.println(Builder.class); } -}""") +}\ +""") .addOutputLines( "BadImportPositiveCases_expected.java", """ @@ -498,7 +501,8 @@ ImmutableList.Builder returnRaw() { void classLiteral() { System.out.println(ImmutableList.Builder.class); } -}""") +}\ +""") .doTest(TestMode.AST_MATCH); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/BadShiftAmountTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/BadShiftAmountTest.java index 7b0eb68bf4f..4a56e6bde5d 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/BadShiftAmountTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/BadShiftAmountTest.java @@ -78,7 +78,8 @@ public void foo() { // BUG: Diagnostic contains: (long) c >>> 32 result += c >>> 32; } - }""") + }\ + """) .doTest(); } @@ -104,7 +105,8 @@ public void foo() { result += x >>> 3; result += (long) (x & 0xff) >> 40; } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/BanClassLoaderTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/BanClassLoaderTest.java index c089d8ab5b0..bae671992d5 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/BanClassLoaderTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/BanClassLoaderTest.java @@ -83,7 +83,8 @@ public static final Class methodHandlesDefineClass(byte[] bytes) // BUG: Diagnostic contains: BanClassLoader return MethodHandles.lookup().defineClass(bytes); } -}""") +}\ +""") .doTest(); } @@ -113,7 +114,8 @@ public final Class overrideClassLoader() throws ClassNotFoundException { private class NotClassLoader { protected void loadClass() {} } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/BanJNDITest.java b/core/src/test/java/com/google/errorprone/bugpatterns/BanJNDITest.java index a5024402357..910ca6986de 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/BanJNDITest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/BanJNDITest.java @@ -169,7 +169,8 @@ private Object subclassesJavaNamingcontext() throws NamingException { // BUG: Diagnostic contains: BanJNDI return c.lookup("hello"); } -}""") +}\ +""") .doTest(); } @@ -197,7 +198,8 @@ class BanJNDIPositiveCases { private void callsList() throws NamingException { FakeDirContext.list(((Name) new Object())); } -}""") +}\ +""") .doTest(); } @@ -225,7 +227,8 @@ class BanJNDIPositiveCases { private void callsList() throws NamingException { FakeDirContext.list(((Name) new Object())); } -}""") +}\ +""") .expectUnchanged() .setArgs("-XepCompilingTestOnlyCode") .doTest(); diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ByteBufferBackingArrayTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ByteBufferBackingArrayTest.java index 7654fa0f6ff..f84c8b94c71 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ByteBufferBackingArrayTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ByteBufferBackingArrayTest.java @@ -104,7 +104,8 @@ void array_precededByNotAValidMethod_isFlagged() { // BUG: Diagnostic contains: ByteBuffer.array() buff.array(); } -}""") +}\ +""") .doTest(); } @@ -248,7 +249,8 @@ void array_inLambdaExpression_precededByByteBufferAllocate_isNotFlagged() { return null; }; } -}""") +}\ +""") .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/CannotMockFinalClassTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/CannotMockFinalClassTest.java index f038e3d0b57..3bdd0e3bab2 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/CannotMockFinalClassTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/CannotMockFinalClassTest.java @@ -56,7 +56,8 @@ public void method() { // BUG: Diagnostic contains: Mockito cannot mock FinalClass local = Mockito.mock(FinalClass.class); } - }""") + }\ + """) .doTest(); } @@ -105,7 +106,8 @@ static class NonFinalClass {} public void method() { NonFinalClass local = Mockito.mock(NonFinalClass.class); } - }""") + }\ + """) .doTest(); } @@ -127,7 +129,8 @@ static final class FinalClass {} public void method() { FinalClass local = Mockito.mock(FinalClass.class); } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ChainedAssertionLosesContextTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ChainedAssertionLosesContextTest.java index 494f0f7140f..dbcc05ffb63 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ChainedAssertionLosesContextTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ChainedAssertionLosesContextTest.java @@ -126,7 +126,8 @@ Foo otherFoo() { return this; } } -}""") +}\ +""") .doTest(); } @@ -190,7 +191,8 @@ Foo otherFoo() { return this; } } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ChainingConstructorIgnoresParameterTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ChainingConstructorIgnoresParameterTest.java index e912ac10e52..ac363a8ff00 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ChainingConstructorIgnoresParameterTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ChainingConstructorIgnoresParameterTest.java @@ -122,7 +122,8 @@ static class MultipleQueuedErrors { enum Location { TEST_TARGET } -}""") +}\ +""") .doTest(); } @@ -232,7 +233,8 @@ static class Varargs2 { this("something"); } } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/CheckReturnValueTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/CheckReturnValueTest.java index 8dd9d36d324..daec8cbf32d 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/CheckReturnValueTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/CheckReturnValueTest.java @@ -229,7 +229,8 @@ public static void ignoresCheck() { check(); } } -}""") +}\ +""") .doTest(); } @@ -347,7 +348,8 @@ public void testMethodReference(boolean predicate) { callSupplier(this::mustCheck); callSupplier(predicate ? this::mustCheck : this::nothingToCheck); } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ClassCanBeStaticTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ClassCanBeStaticTest.java index 04eb27e00be..b8182650abc 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ClassCanBeStaticTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ClassCanBeStaticTest.java @@ -113,7 +113,8 @@ int localMethod() { } } } - }""") + }\ + """) .setArgs("--release", "11") .doTest(); } @@ -138,7 +139,8 @@ public class ClassCanBeStaticPositiveCase1 { class Inner1 { int innerVar; } - }""") + }\ + """) .doTest(); } @@ -168,7 +170,8 @@ int localMethod(int outerVar2) { return outerVar2; } } - }""") + }\ + """) .doTest(); } @@ -193,7 +196,8 @@ static class NonStaticOuter { // BUG: Diagnostic contains: public static class Inner3 public class Inner3 {} } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/CollectionToArraySafeParameterTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/CollectionToArraySafeParameterTest.java index 83db1c94113..74c01c08a3a 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/CollectionToArraySafeParameterTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/CollectionToArraySafeParameterTest.java @@ -77,7 +77,8 @@ void test(FooBar foo) { class FooBar extends HashSet {} class Foo extends HashSet {} - }""") + }\ + """) .doTest(); } @@ -141,7 +142,8 @@ Integer[] toArray(Integer[] someArray) { return new Integer[10]; } } -}""") +}\ +""") .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/CollectorShouldNotUseStateTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/CollectorShouldNotUseStateTest.java index 687ffb869e1..53a382a5f61 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/CollectorShouldNotUseStateTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/CollectorShouldNotUseStateTest.java @@ -87,7 +87,8 @@ public void accept(Builder objectBuilder, Object o) { (left, right) -> left.addAll(right.build()), ImmutableList.Builder::build); } - }""") + }\ + """) .doTest(); } @@ -126,7 +127,8 @@ public void accept(Builder objectBuilder, Object o) { (left, right) -> left.addAll(right.build()), ImmutableList.Builder::build); } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ComparableAndComparatorTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ComparableAndComparatorTest.java index 353f8aae6a3..9e98d0e1a5e 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ComparableAndComparatorTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ComparableAndComparatorTest.java @@ -75,7 +75,8 @@ public int compareTo(SubClass o) { return 0; } } - }""") + }\ + """) .doTest(); } @@ -161,7 +162,8 @@ public int compare(Integer one, Integer two) { return 0; } } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ComparableTypeTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ComparableTypeTest.java index cce753effe1..92500df8428 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ComparableTypeTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ComparableTypeTest.java @@ -149,7 +149,8 @@ public int compareTo(Integer o) { return 0; } } -}""") +}\ +""") .doTest(); } @@ -255,7 +256,8 @@ public int compareTo(Object o) { return 0; } } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ComparisonContractViolatedTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ComparisonContractViolatedTest.java index d2c421320a9..62d459ba035 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ComparisonContractViolatedTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ComparisonContractViolatedTest.java @@ -143,7 +143,8 @@ public int compare(Struct o1, Struct o2) { return o1.equals(o2) ? 0 : POSITIVE_CONSTANT; } }; - }""") + }\ + """) .doTest(); } @@ -179,7 +180,8 @@ public int compareTo(IntOrInfinity o) { return (o instanceof NegativeInfinity) ? 0 : -1; } } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ComparisonOutOfRangeTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ComparisonOutOfRangeTest.java index 59e1ccdb51c..f25dcedde72 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ComparisonOutOfRangeTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ComparisonOutOfRangeTest.java @@ -166,7 +166,8 @@ void longs(long l) { // BUG: Diagnostic contains: false result = l == Long.MIN_VALUE * 2.0; } - }""") + }\ + """) .doTest(); } @@ -277,7 +278,8 @@ void longs(long l) { String binaryTreeMixingByteWithNonNumeric(byte b) { return "value is: " + b; } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/DeadExceptionTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/DeadExceptionTest.java index 4932feabfcb..95ccc22f351 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/DeadExceptionTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/DeadExceptionTest.java @@ -98,7 +98,8 @@ public void testLooksLikeAJunitTestMethod() { // BUG: Diagnostic contains: throw new Exception new Exception(); } - }""") + }\ + """) .doTest(); } @@ -120,7 +121,8 @@ public void noError() { public Exception returnsException() { return new RuntimeException("returned"); } - }""") + }\ + """) .doTest(); } @@ -162,7 +164,8 @@ public void shouldAllowTestingOfExceptionConstructorSideEffects() { // expected } } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/DepAnnTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/DepAnnTest.java index 3c89147ad34..a78c3f2ee17 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/DepAnnTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/DepAnnTest.java @@ -76,7 +76,8 @@ interface Interface {} */ // BUG: Diagnostic contains: @Deprecated public void deprecatedMethood() {} - }""") + }\ + """) .doTest(); } @@ -139,7 +140,8 @@ public void deprecatedMethodWithMalformedComment() {} public void suppressed() {} public void newMethod() {} - }""") + }\ + """) .doTest(); } @@ -175,7 +177,8 @@ class SummaryRowKey

{} public abstract void m2(); } - }""") + }\ + """) .doTest(); } @@ -226,7 +229,8 @@ interface Interface {} */ // BUG: Diagnostic contains: @Deprecated public void deprecatedMethood() {} - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/EmptyCatchTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/EmptyCatchTest.java index 0382293f9ca..a4f96d06a06 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/EmptyCatchTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/EmptyCatchTest.java @@ -73,7 +73,8 @@ public void expectedException() { } catch (Exception expected) { } } - }""") + }\ + """) .doTest(); } @@ -193,7 +194,8 @@ public void catchIsLoggedOnly() { System.out.println("Caught an exception: " + t); } } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/EmptyIfStatementTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/EmptyIfStatementTest.java index 0e6e1f3a66a..5cfcb679920 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/EmptyIfStatementTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/EmptyIfStatementTest.java @@ -85,7 +85,8 @@ public static void positiveCase5() { System.out.println("foo"); } } - }""") + }\ + """) .doTest(); } @@ -129,7 +130,8 @@ else if (i == 12) ; else System.out.println("not 10, 11, or 12"); } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/EqualsHashCodeTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/EqualsHashCodeTest.java index 20b823c8a4e..460d77cd48d 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/EqualsHashCodeTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/EqualsHashCodeTest.java @@ -42,7 +42,8 @@ public boolean equals(Object o) { return false; } } -}""") +}\ +""") .doTest(); } @@ -71,7 +72,8 @@ public int hashCode() { } public static class Neither {} - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/EqualsIncompatibleTypeTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/EqualsIncompatibleTypeTest.java index 75cb3095c06..fd5529c29d3 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/EqualsIncompatibleTypeTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/EqualsIncompatibleTypeTest.java @@ -194,7 +194,8 @@ void testSomeGenerics( // BUG: Diagnostic contains: T and String are incompatible iClazz.equals(strClazz); } -}""") +}\ +""") .doTest(); } @@ -392,7 +393,8 @@ abstract class F2 { void checkOtherEquals(F1 f1, F2 f2) { f2.equals(f1); } - }""") + }\ + """) .doTest(); } @@ -527,7 +529,8 @@ void something(J j1, J j2) { // Technically this could work, since there's nothing stopping A1 == A2, etc. boolean equals = j1.equals(j2); } -}""") +}\ +""") .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/EqualsNaNTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/EqualsNaNTest.java index 9ed6d8061af..bee6f7fd51a 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/EqualsNaNTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/EqualsNaNTest.java @@ -60,7 +60,8 @@ public class EqualsNaNPositiveCases { // BUG: Diagnostic contains: Double.isNaN(123456) static final boolean INT_IS_NAN = 123456 == Double.NaN; - }""") + }\ + """) .doTest(); } @@ -78,7 +79,8 @@ public void negativeCase() { public class EqualsNaNNegativeCases { static final boolean NAN_AFTER_MATH = (0.0 / 0.0) == 1.0; static final boolean NORMAL_COMPARISON = 1.0 == 2.0; - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/EqualsReferenceTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/EqualsReferenceTest.java index cd7d42cae63..ae35efb3e6b 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/EqualsReferenceTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/EqualsReferenceTest.java @@ -71,7 +71,8 @@ public boolean equals(Object o) { return equals(o); } } - }""") + }\ + """) .doTest(); } @@ -146,7 +147,8 @@ public Object getValue() { return null; } } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ErroneousThreadPoolConstructorCheckerTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ErroneousThreadPoolConstructorCheckerTest.java index bb1fefe98c7..687b803bcf7 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ErroneousThreadPoolConstructorCheckerTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ErroneousThreadPoolConstructorCheckerTest.java @@ -127,7 +127,8 @@ private void createThreadPoolWithUnboundedPriorityBlockingQueue( SECONDS, new PriorityBlockingQueue<>(initialCapacity, comparingInt(Object::hashCode))); } -}""") +}\ +""") .doTest(); } @@ -215,7 +216,8 @@ private void createThreadPoolWithBoundedSynchronousQueue() { new ThreadPoolExecutor( CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME, SECONDS, new SynchronousQueue<>()); } -}""") +}\ +""") .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/FallThroughTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/FallThroughTest.java index 7d2eb947a1f..ab4e645f498 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/FallThroughTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/FallThroughTest.java @@ -109,7 +109,8 @@ public int everyBodyIsDoingIt(int a, int b) { return 0; } } - }""") + }\ + """) .doTest(); } @@ -264,7 +265,8 @@ int foo(int i) { } } } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/FinallyTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/FinallyTest.java index b00d773ed64..3afcd32819a 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/FinallyTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/FinallyTest.java @@ -165,7 +165,8 @@ public void test8() { } } } -}""") +}\ +""") .doTest(); } @@ -290,7 +291,8 @@ public void throwFromNestedCatchInFinally() throws Exception { } } } - }""") + }\ + """) .doTest(); } @@ -379,7 +381,8 @@ public void test7() { } } } - }""") + }\ + """) .doTest(); } @@ -448,7 +451,8 @@ public void nestedTryInFinally2() throws Exception { } } } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/FloatingPointAssertionWithinEpsilonTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/FloatingPointAssertionWithinEpsilonTest.java index e44212ff07b..3b397a77ec8 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/FloatingPointAssertionWithinEpsilonTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/FloatingPointAssertionWithinEpsilonTest.java @@ -90,7 +90,8 @@ public void testDouble() { // BUG: Diagnostic contains: 1.1e-16 assertEquals("equal!", 1.0, 1.0, TOLERANCE2); } - }""") + }\ + """) .doTest(); } @@ -145,7 +146,8 @@ public void testZeroCases() { assertEquals(1f, 1f, 0f); } - }""") + }\ + """) .doTest(); } @@ -207,7 +209,8 @@ public void testDouble() { // BUG: Diagnostic contains: 1.1e-16 assertEquals("equal!", 1.0, 1.0, TOLERANCE2); } - }""") + }\ + """) .addOutputLines( "FloatingPointAssertionWithinEpsilonPositiveCases_expected.java", """ @@ -245,7 +248,8 @@ public void testDouble() { assertEquals(1.0, 1.0, 0); assertEquals("equal!", 1.0, 1.0, 0); } - }""") + }\ + """) .doTest(TestMode.AST_MATCH); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/FunctionalInterfaceMethodChangedTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/FunctionalInterfaceMethodChangedTest.java index 16861402b2e..770ebafb7fc 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/FunctionalInterfaceMethodChangedTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/FunctionalInterfaceMethodChangedTest.java @@ -126,7 +126,8 @@ default String superSam() { return null; } } - }""") + }\ + """) .doTest(); } @@ -203,7 +204,8 @@ default Void call() throws Exception { return null; } } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/FutureReturnValueIgnoredTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/FutureReturnValueIgnoredTest.java index cf778ea4121..a7ea95e7a0e 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/FutureReturnValueIgnoredTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/FutureReturnValueIgnoredTest.java @@ -238,7 +238,8 @@ public Object apply(Object string) { }, runnable -> runnable.run()); } -}""") +}\ +""") .doTest(); } @@ -540,7 +541,8 @@ protected Object handleInvocation(Object o, Method method, Object[] params) { } }; } -}""") +}\ +""") .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/FuturesGetCheckedIllegalExceptionTypeTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/FuturesGetCheckedIllegalExceptionTypeTest.java index e2dc3bcad25..db141f55146 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/FuturesGetCheckedIllegalExceptionTypeTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/FuturesGetCheckedIllegalExceptionTypeTest.java @@ -94,7 +94,8 @@ public InnerClassWithExplicitConstructorException() {} } public class InnerClassWithImplicitConstructorException extends Exception {} -}""") +}\ +""") .doTest(); } @@ -147,7 +148,8 @@ public static class StaticNestedWithImplicitConstructorException extends Excepti public static class ProtectedConstructorException extends Exception { protected ProtectedConstructorException() {} } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/FuzzyEqualsShouldNotBeUsedInEqualsMethodTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/FuzzyEqualsShouldNotBeUsedInEqualsMethodTest.java index b8f58f6882e..352b2294723 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/FuzzyEqualsShouldNotBeUsedInEqualsMethodTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/FuzzyEqualsShouldNotBeUsedInEqualsMethodTest.java @@ -58,7 +58,8 @@ public boolean equals(Object other) { return DoubleMath.fuzzyEquals(x, y, z); } } - }""") + }\ + """) .doTest(); } @@ -93,7 +94,8 @@ public boolean equals(Object other, double a) { return DoubleMath.fuzzyEquals(0, 1, 0.2); } } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/GetClassOnClassTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/GetClassOnClassTest.java index 815375bf824..9e7acdd0ae8 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/GetClassOnClassTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/GetClassOnClassTest.java @@ -59,7 +59,8 @@ public void getClassOnClass3() { // BUG: Diagnostic contains: String.class.getName() System.out.println(String.class.getClass().getName()); } - }""") + }\ + """) .doTest(); } @@ -91,7 +92,8 @@ public static boolean getClass(Object a) { return true; } } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/HidingFieldTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/HidingFieldTest.java index 3daa3f6abaf..eb9f983a160 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/HidingFieldTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/HidingFieldTest.java @@ -95,7 +95,8 @@ public static class ClassG extends ClassF { // BUG: Diagnostic contains: superclass: ClassF String varThree; } -}""") +}\ +""") .addSourceLines( "HidingFieldPositiveCases2.java", """ @@ -124,7 +125,8 @@ public class ClassB extends HidingFieldPositiveCases1.ClassB { // BUG: Diagnostic contains: superclass: ClassA public int varOne = 2; } -}""") +}\ +""") .doTest(); } @@ -178,7 +180,8 @@ public void varThree() {} public void varTwo() {} } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ImplementAssertionWithChainingTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ImplementAssertionWithChainingTest.java index 488012b49c9..27942d51a16 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ImplementAssertionWithChainingTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ImplementAssertionWithChainingTest.java @@ -125,7 +125,8 @@ Foo otherFoo() { } private enum Kind {} -}""") +}\ +""") .doTest(); } @@ -198,7 +199,8 @@ Foo otherFoo() { return this; } } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/InconsistentCapitalizationTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/InconsistentCapitalizationTest.java index c0460ceb5ed..fe8bb976b78 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/InconsistentCapitalizationTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/InconsistentCapitalizationTest.java @@ -194,7 +194,8 @@ static class Child extends Parent { } } } -}""") +}\ +""") .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/IncrementInForLoopAndHeaderTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/IncrementInForLoopAndHeaderTest.java index 8ee5dd68783..0ef8c3ad0d0 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/IncrementInForLoopAndHeaderTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/IncrementInForLoopAndHeaderTest.java @@ -116,7 +116,8 @@ public void expressionStatement() { // BUG: Diagnostic contains: increment for (int i = 0; i < 10; i++) i++; } - }""") + }\ + """) .doTest(); } @@ -189,7 +190,8 @@ public void otherVarInc() { a++; } } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/InsecureCipherModeTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/InsecureCipherModeTest.java index 0c0cbfaa347..8d59d2fa8fe 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/InsecureCipherModeTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/InsecureCipherModeTest.java @@ -257,7 +257,8 @@ public void keyOperations(StringProvider provider) { // We don't handle any exception as this code is not meant to be executed. } } -}""") +}\ +""") .doTest(); } @@ -410,7 +411,8 @@ public void ellipticCurveDiffieHellman() { // We don't handle any exception as this code is not meant to be executed. } } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/InstanceOfAndCastMatchWrongTypeTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/InstanceOfAndCastMatchWrongTypeTest.java index abdf04bf1df..eabcdd1a67a 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/InstanceOfAndCastMatchWrongTypeTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/InstanceOfAndCastMatchWrongTypeTest.java @@ -192,7 +192,8 @@ public static String testCall() { } } - class SuperClass {}""") + class SuperClass {}\ + """) .doTest(); } @@ -470,7 +471,8 @@ static class SuperNegativeClass {} static class SubNegativeClass extends SuperNegativeClass {} static class DisjointClass {} -}""") +}\ +""") .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/InvalidPatternSyntaxTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/InvalidPatternSyntaxTest.java index 9ce3d39d738..85990470c26 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/InvalidPatternSyntaxTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/InvalidPatternSyntaxTest.java @@ -67,7 +67,8 @@ public class InvalidPatternSyntaxPositiveCases { // BUG: Diagnostic contains: "".split(INVALID, 0); } - }""") + }\ + """) .doTest(); } @@ -104,7 +105,8 @@ public void foo(String x) { "".split(x); "".split(x, 0); } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/IterableAndIteratorTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/IterableAndIteratorTest.java index 28dda8e892c..da5aaa53a5b 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/IterableAndIteratorTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/IterableAndIteratorTest.java @@ -143,7 +143,8 @@ public Iterator iterator() { return this; } } -}""") +}\ +""") .doTest(); } @@ -214,7 +215,8 @@ public Iterator iterator() { return l; } } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/JUnit3TestNotRunTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/JUnit3TestNotRunTest.java index 366631a087b..a6c7ad88ba7 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/JUnit3TestNotRunTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/JUnit3TestNotRunTest.java @@ -66,7 +66,8 @@ public void tesgName() {} // tentative - can cause false positives // BUG: Diagnostic contains: JUnit3TestNotRun public void textName() {} - }""") + }\ + """) .doTest(); } @@ -401,7 +402,8 @@ public void ignoredTest2() {} @Ignore @Test public void ignoredTest() {} - }""") + }\ + """) .doTest(); } @@ -437,7 +439,8 @@ public void tstName() {} @Test public void TestName() {} - }""") + }\ + """) .doTest(); } @@ -469,7 +472,8 @@ public void tesMisspelled() {} @Test public void tesBothIssuesAtOnce() {} - }""") + }\ + """) .doTest(); } @@ -498,7 +502,8 @@ public void tesMisspelled() {} @Test public void tesBothIssuesAtOnce() {} -}""") +}\ +""") .doTest(); } @@ -530,7 +535,8 @@ public void tesMisspelled() {} @Test public void tesBothIssuesAtOnce() {} - }""") + }\ + """) // needed as a dependency .addSourceLines( "JUnit3TestNotRunNegativeCase5.java", @@ -555,7 +561,8 @@ public void tesMisspelled() {} @Test public void tesBothIssuesAtOnce() {} - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/JUnit4SetUpNotRunTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/JUnit4SetUpNotRunTest.java index 9412760815e..f67fa13bc9e 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/JUnit4SetUpNotRunTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/JUnit4SetUpNotRunTest.java @@ -110,7 +110,8 @@ class J4OverriddenSetUp extends BaseTestClass { class J4OverriddenSetUpPublic extends BaseTestClass { // BUG: Diagnostic contains: @Before @Override public void setUp() {} -}""") +}\ +""") .doTest(); } @@ -134,7 +135,8 @@ public class JUnit4SetUpNotRunPositiveCaseCustomBefore { public void setUp() {} } - @interface Before {}""") + @interface Before {}\ + """) .doTest(); } @@ -201,7 +203,8 @@ public void initMocks() {} protected void badVisibility() {} } - @interface Before {}""") + @interface Before {}\ + """) .doTest(); } @@ -288,7 +291,8 @@ public void setUp() {} @RunWith(JUnit4.class) class J4SetUpExtendsAnnotatedMethod extends SetUpAnnotatedBaseClass { public void setUp() {} -}""") +}\ +""") .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/JUnit4TearDownNotRunTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/JUnit4TearDownNotRunTest.java index e665cdbdf0f..2503b07d03a 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/JUnit4TearDownNotRunTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/JUnit4TearDownNotRunTest.java @@ -90,7 +90,8 @@ class J4TearDownHasOverride extends TearDownUnannotatedBaseClass { class J4TearDownHasPublicOverride extends TearDownUnannotatedBaseClass { // BUG: Diagnostic contains: @After @Override public void tearDown() {} - }""") + }\ + """) .doTest(); } @@ -114,7 +115,8 @@ public class JUnit4TearDownNotRunPositiveCaseCustomAfter { public void tearDown() {} } - @interface After {}""") + @interface After {}\ + """) .doTest(); } @@ -138,7 +140,8 @@ public class JUnit4TearDownNotRunPositiveCaseCustomAfter2 { public void tidyUp() {} } - @interface After {}""") + @interface After {}\ + """) .doTest(); } @@ -222,7 +225,8 @@ public void tearDown() {} class J4TearDownInheritsFromAnnotatedMethod2 extends TearDownAnnotatedBaseClass { @After public void tearDown() {} - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/JUnit4TestNotRunTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/JUnit4TestNotRunTest.java index 59b86392000..404c367b61e 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/JUnit4TestNotRunTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/JUnit4TestNotRunTest.java @@ -56,7 +56,8 @@ public void testThisIsATest() {} // BUG: Diagnostic contains: @Test public static void testThisIsAStaticTest() {} - }""") + }\ + """) .doTest(); } @@ -83,7 +84,8 @@ public void testThisIsATest() {} // BUG: Diagnostic contains: @Test public static void testThisIsAStaticTest() {} - }""") + }\ + """) .doTest(); } @@ -653,7 +655,8 @@ public void negativeCase1() { */ public class JUnit4TestNotRunNegativeCase1 { public void testThisIsATest() {} - }""") + }\ + """) .doTest(); } @@ -676,7 +679,8 @@ public void negativeCase2() { @RunWith(JUnit38ClassRunner.class) public class JUnit4TestNotRunNegativeCase2 { public void testThisIsATest() {} - }""") + }\ + """) .doTest(); } @@ -726,7 +730,8 @@ public void testTest3(int foo) {} public int testSomething() { return 42; } -}""") +}\ +""") .doTest(); } @@ -750,7 +755,8 @@ public void negativeCase4() { @RunWith(JUnit4.class) public class JUnit4TestNotRunNegativeCase4 extends TestCase { public void testThisIsATest() {} -}""") +}\ +""") .doTest(); } @@ -783,7 +789,8 @@ public void testTearDown() {} @Test public void testOverrideThis() {} - }""") + }\ + """) .addSourceLines( "JUnit4TestNotRunNegativeCase5.java", """ @@ -807,7 +814,8 @@ public void testTearDown() {} @Override public void testOverrideThis() {} -}""") +}\ +""") .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/JUnitAssertSameCheckTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/JUnitAssertSameCheckTest.java index 36ed0ba988a..3f1ef7827b0 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/JUnitAssertSameCheckTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/JUnitAssertSameCheckTest.java @@ -64,7 +64,8 @@ public void test(Object obj) { // BUG: Diagnostic contains: An object is tested for reference equality to itself using JUnit junit.framework.Assert.assertSame("message", obj, obj); } -}""") +}\ +""") .doTest(); } @@ -89,7 +90,8 @@ public void test(Object obj1, Object obj2) { junit.framework.Assert.assertSame(obj1, obj2); junit.framework.Assert.assertSame("message", obj1, obj2); } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/JUnitParameterMethodNotFoundTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/JUnitParameterMethodNotFoundTest.java index 3df8bc05499..eba7e08f5ab 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/JUnitParameterMethodNotFoundTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/JUnitParameterMethodNotFoundTest.java @@ -160,7 +160,8 @@ public Object dataProviderInner() { return new Object[] {1}; } } -}""") +}\ +""") .doTest(); } @@ -182,7 +183,8 @@ public class JUnitParameterMethodNotFoundNegativeCaseNonJUnitParamsRunner { @Test @Parameters(method = "named1") public void paramStaticProvider() {} - }""") + }\ + """) .doTest(); } @@ -202,7 +204,8 @@ public abstract class JUnitParameterMethodNotFoundNegativeCaseBaseClass { public Object named1() { return new Object[] {1}; } - }""") + }\ + """) .addSourceLines( "JUnitParameterMethodNotFoundNegativeCaseSuperClass.java", """ @@ -219,7 +222,8 @@ public class JUnitParameterMethodNotFoundNegativeCaseSuperClass @Test @Parameters(method = "named1") public void testNamed(int a) {} - }""") + }\ + """) .doTest(); } @@ -259,7 +263,8 @@ public Object dataProvider() { return new Object[] {1}; } } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/LambdaFunctionalInterfaceTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/LambdaFunctionalInterfaceTest.java index 06dd80ce5f2..121c732687f 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/LambdaFunctionalInterfaceTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/LambdaFunctionalInterfaceTest.java @@ -196,7 +196,8 @@ public int getSumAll() { return sumAll(o -> 2); } } -}""") +}\ +""") .doTest(); } @@ -293,7 +294,8 @@ public Double getMu() { return findOptimalMuLambda(mu -> 0L, 3.0); } } -}""") +}\ +""") .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/LiteEnumValueOfTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/LiteEnumValueOfTest.java index 39f35ea3081..8b5d58976fa 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/LiteEnumValueOfTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/LiteEnumValueOfTest.java @@ -36,7 +36,8 @@ public final class LiteEnumValueOfTest { """ package android.os; - public interface Parcel {}""") + public interface Parcel {}\ + """) .addSourceLines( "Parcelable.java", """ @@ -56,7 +57,8 @@ interface Creator { interface ClassLoaderCreator extends Creator { T createFromParcel(Parcel source, ClassLoader loader); } - }""") + }\ + """) .addSourceLines( "FakeLiteEnum.java", """ diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/LockOnNonEnclosingClassLiteralTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/LockOnNonEnclosingClassLiteralTest.java index 0e7bf3d65c4..4aeaefded5c 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/LockOnNonEnclosingClassLiteralTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/LockOnNonEnclosingClassLiteralTest.java @@ -60,7 +60,8 @@ public void methodContainsSynchronizedBlock() { } } } -}""") +}\ +""") .doTest(); } @@ -93,7 +94,8 @@ public void methodContainsSynchronizedBlock() { } } } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/LongLiteralLowerCaseSuffixTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/LongLiteralLowerCaseSuffixTest.java index d7e4a00fca3..bb2dbb105ed 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/LongLiteralLowerCaseSuffixTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/LongLiteralLowerCaseSuffixTest.java @@ -117,7 +117,8 @@ public void negativeOctalExtraSpacesLowerCase() { long value = - 06543l; } -}""") +}\ +""") .doTest(); } @@ -142,7 +143,8 @@ public void underscoredLowerCase() { // BUG: Diagnostic contains: value = 0_1__2L long value = 0_1__2l; } -}""") +}\ +""") .doTest(); } @@ -200,7 +202,8 @@ public void zeroHexUpperCase() { public void negativeHexUpperCase() { long value = -0x80L; } - }""") + }\ + """) .doTest(); } @@ -290,7 +293,8 @@ public void negativeOctalExtraSpacesLowerCase() { long value = - 06543l; } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/MisleadingEscapedSpaceTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/MisleadingEscapedSpaceTest.java index 8bfa78708b2..ab2fb40ec07 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/MisleadingEscapedSpaceTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/MisleadingEscapedSpaceTest.java @@ -39,7 +39,8 @@ public void misleadingEscape() { class Test { // BUG: Diagnostic contains: private static final String FOO = " \\s "; - }""") + }\ + """) .doTest(); } @@ -53,7 +54,8 @@ public void literalBackslashS() { """ class Test { private static final String FOO = " \\\\s "; - }""") + }\ + """) .doTest(); } @@ -68,7 +70,8 @@ public void asSingleCharacter_misleading() { class Test { // BUG: Diagnostic contains: private static final char x = '\\s'; - }""") + }\ + """) .doTest(); } @@ -90,7 +93,8 @@ class Test { foo \\s bar \\s baz \"""; - }""") + }\ + """) .doTest(); } @@ -107,7 +111,8 @@ class Test { foo \\s bar \\s \"""; - }""") + }\ + """) .doTest(); } @@ -123,7 +128,8 @@ class Test { private static final String FOO = \""" foo \\s\\s\\s\\s \"""; - }""") + }\ + """) .doTest(); } @@ -137,7 +143,8 @@ public void withinCommentInBrokenUpString_noFinding() { """ class Test { private static final String FOO = "foo" + /* \\s */ " bar"; - }""") + }\ + """) .doTest(); } @@ -170,7 +177,8 @@ public void escapedSpaceAtEndOfString() { class Test { // BUG: Diagnostic contains: private static final String FOO = "foo\\s"; - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/MissingFailTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/MissingFailTest.java index b9a985b27e3..afbea6d9e40 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/MissingFailTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/MissingFailTest.java @@ -176,7 +176,8 @@ private static void dummyMethod() {} private static void assertDummy() {} private static void verifyDummy() {} - }""") + }\ + """) .doTest(); } @@ -216,7 +217,8 @@ public void expectedException_helperMethod() { } private static void dummyMethod() {} - }""") + }\ + """) .doTest(); } @@ -257,7 +259,8 @@ public void catchAssert() { private static void dummyMethod() {} private static void assertDummy() {} - }""") + }\ + """) .doTest(); } @@ -728,7 +731,8 @@ String dummy() { return ""; } } -}""") +}\ +""") .doTest(); } @@ -761,7 +765,8 @@ public void catchAssert() { private static void dummyMethod() {} private static void assertDummy() {} - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/MisusedWeekYearTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/MisusedWeekYearTest.java index 54242d0601a..3b9f57aab2b 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/MisusedWeekYearTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/MisusedWeekYearTest.java @@ -128,7 +128,8 @@ void testDateTimeFormatter() { // BUG: Diagnostic contains: java.time.format.DateTimeFormatter.ofPattern(WEEK_YEAR_PATTERN); } -}""") +}\ +""") .doTest(); } @@ -175,7 +176,8 @@ void testApplyPatternAndApplyLocalizedPattern() { // BUG: Diagnostic contains: sdf.applyLocalizedPattern("YYYY-MM-dd"); } -}""") +}\ +""") .doTest(); } @@ -228,7 +230,8 @@ void testSubtype() { mySdf.applyPattern("YYYY-MM-dd"); mySdf.applyLocalizedPattern("YYYY-MM-dd"); } -}""") +}\ +""") .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ModifyCollectionInEnhancedForLoopTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ModifyCollectionInEnhancedForLoopTest.java index 95fdf4c076e..f245aa2c6c3 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ModifyCollectionInEnhancedForLoopTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ModifyCollectionInEnhancedForLoopTest.java @@ -127,7 +127,8 @@ public static void testMapEntrySet(HashMap map) { map.remove(a.getKey()); } } - }""") + }\ + """) .doTest(); } @@ -233,7 +234,8 @@ private static void customConcurrent(MyBlockingQueue mbq) { mbq.add(i); } } -}""") +}\ +""") .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ModifySourceCollectionInStreamTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ModifySourceCollectionInStreamTest.java index 94d9f6e8b5b..96cb6aecbaa 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ModifySourceCollectionInStreamTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ModifySourceCollectionInStreamTest.java @@ -116,7 +116,8 @@ private List mutateStreamSourceLambdaExpression( private List getMutableValues() { return mutableValues; } -}""") +}\ +""") .doTest(); } @@ -224,7 +225,8 @@ private interface CustomContainer { boolean add(T t); } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ModifyingCollectionWithItselfTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ModifyingCollectionWithItselfTest.java index e1f5c62aa51..ad23e1fe045 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ModifyingCollectionWithItselfTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ModifyingCollectionWithItselfTest.java @@ -102,7 +102,8 @@ void expressionStatementChecks() { b = a.removeAll(a); } } - }""") + }\ + """) .doTest(); } @@ -139,7 +140,8 @@ public boolean retainAll(List b) { public boolean containsAll(List b) { return a.containsAll(b); } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/MultipleParallelOrSequentialCallsTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/MultipleParallelOrSequentialCallsTest.java index b8a4c320427..912b07c948f 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/MultipleParallelOrSequentialCallsTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/MultipleParallelOrSequentialCallsTest.java @@ -176,7 +176,8 @@ private boolean testClass() { return true; } } -}""") +}\ +""") .doTest(); } @@ -236,7 +237,8 @@ public SomeObject parallel() { return null; } } - }""") + }\ + """) .doTest(); } @@ -377,7 +379,8 @@ private boolean testClass() { return true; } } -}""") +}\ +""") .addOutputLines( "MultipleParallelOrSequentialCallsPositiveCases_expected.java", """ @@ -506,7 +509,8 @@ private boolean testClass() { return true; } } -}""") +}\ +""") .doTest(TestMode.AST_MATCH); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/MultipleUnaryOperatorsInMethodCallTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/MultipleUnaryOperatorsInMethodCallTest.java index 7157796044e..cd151e5e8e4 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/MultipleUnaryOperatorsInMethodCallTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/MultipleUnaryOperatorsInMethodCallTest.java @@ -73,7 +73,8 @@ public static void threeArgs(int a, int b, int c) {} public static int someFunction(int a) { return 0; } - }""") + }\ + """) .doTest(); } @@ -101,7 +102,8 @@ public static void tests(int a, int b, int[] xs) { } public static void testMethod(int one, int two) {} - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/NestedInstanceOfConditionsTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/NestedInstanceOfConditionsTest.java index 97a39f1f498..64df764781c 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/NestedInstanceOfConditionsTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/NestedInstanceOfConditionsTest.java @@ -111,7 +111,8 @@ static class ClassA {} static class ClassB {} static class ClassC {} - }""") + }\ + """) .doTest(); } @@ -209,7 +210,8 @@ public static class SubClass extends SuperClass {} /** test class */ public static class DisjointClass {} ; -}""") +}\ +""") .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/NoAllocationCheckerTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/NoAllocationCheckerTest.java index 5fc2c51cc60..b280af967a1 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/NoAllocationCheckerTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/NoAllocationCheckerTest.java @@ -541,7 +541,8 @@ public static class NoAllocationSubclass extends NoAllocationParentClass { // BUG: Diagnostic contains: @NoAllocation public void method() {} } - }""") + }\ + """) .doTest(); } @@ -1081,7 +1082,8 @@ public static class NoAllocationSubclassWithSuppression extends NoAllocationPare @SuppressWarnings("NoAllocation") public void method() {} } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/NonAtomicVolatileUpdateTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/NonAtomicVolatileUpdateTest.java index 84dc6559c8d..491e3e9803c 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/NonAtomicVolatileUpdateTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/NonAtomicVolatileUpdateTest.java @@ -103,7 +103,8 @@ public void stringUpdate() { // BUG: Diagnostic contains: myVolatileString = myVolatileString + "update"; } - }""") + }\ + """) .doTest(); } @@ -167,7 +168,8 @@ public void synchronizedBlock() { myVolatileString = myVolatileString + "update"; } } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/NonRuntimeAnnotationTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/NonRuntimeAnnotationTest.java index 3d4857b48f6..fb422d52ea4 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/NonRuntimeAnnotationTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/NonRuntimeAnnotationTest.java @@ -65,7 +65,8 @@ public NonRuntime testAnnotation() { /** Annotation that is implicitly NOT retained at runtime */ public @interface NotSpecified {} -}""") +}\ +""") .doTest(); } @@ -93,7 +94,8 @@ public Runtime testAnnotation() { /** Annotation that is retained at runtime */ @Retention(RetentionPolicy.RUNTIME) public @interface Runtime {} -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ObjectToStringTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ObjectToStringTest.java index bd0b9b31e6b..b47c11ae80b 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ObjectToStringTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ObjectToStringTest.java @@ -68,7 +68,8 @@ void genericClassShowsErasure() { // BUG: Diagnostic contains: `FinalGenericClassWithoutToString@ System.out.println(finalGenericClassWithoutToString.toString()); } - }""") + }\ + """) .doTest(); } @@ -148,7 +149,8 @@ public void overridePresentInAbstractClassInHierarchy(Duration durationArg) { unusedString = durationArg.toString(); System.out.println("test joda string " + durationArg); } -}""") +}\ +""") .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/OptionalNotPresentTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/OptionalNotPresentTest.java index b5930f6f9d3..9d3670d1cd6 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/OptionalNotPresentTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/OptionalNotPresentTest.java @@ -89,7 +89,8 @@ public String getWhenPresent_nestedCheck(Optional optional) { } return ""; } - }""") + }\ + """) .doTest(); } @@ -196,7 +197,8 @@ public String getWhenAbsent_methodScoped(Optional optional) { } return optional.get(); } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/OverrideThrowableToStringTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/OverrideThrowableToStringTest.java index 20dd1e403f5..8047b80ee9a 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/OverrideThrowableToStringTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/OverrideThrowableToStringTest.java @@ -72,7 +72,8 @@ public String toString() { return ""; } } - }""") + }\ + """) .doTest(); } @@ -118,7 +119,8 @@ public String getMessage() { return ""; } } - }""") + }\ + """) .doTest(); } @@ -164,7 +166,8 @@ public String toString() { return ""; } } - }""") + }\ + """) .addOutputLines( "OverrideThrowableToStringPositiveCases_expected.java", """ @@ -202,7 +205,8 @@ public String getMessage() { return ""; } } - }""") + }\ + """) .doTest(TestMode.AST_MATCH); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/OverridesTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/OverridesTest.java index c077fa07b61..920e907b982 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/OverridesTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/OverridesTest.java @@ -122,7 +122,8 @@ abstract class ImplementsAndExtends2 extends MyBase implements MyInterface { // BUG: Diagnostic contains: public abstract void g(Object... xs); } -}""") +}\ +""") .doTest(); } @@ -163,7 +164,8 @@ abstract class SubThree extends SubTwo { // BUG: Diagnostic contains: abstract void varargsMethod(Object[] newNames); } -}""") +}\ +""") .doTest(); } @@ -204,7 +206,8 @@ abstract class SubThree extends SubTwo { // BUG: Diagnostic contains: abstract void arrayMethod(Object... newNames); } -}""") +}\ +""") .doTest(); } @@ -244,7 +247,8 @@ abstract class Child2 extends Base { // BUG: Diagnostic contains: Varargs abstract void varargsMethod(@Note final Map /*dsa*/ [ /* [ */ ] /* dsa */ xs); } -}""") +}\ +""") .doTest(); } @@ -281,7 +285,8 @@ void foo(Base base) { base.varargsMethod(null, new Object[] {}, new Object[] {}, new Object[] {}, new Object[] {}); } } -}""") +}\ +""") .doTest(); } @@ -362,7 +367,8 @@ public Builder varargsMethod(String... args) { return this; } } -}""") +}\ +""") .doTest(); } @@ -396,7 +402,8 @@ abstract class SubThree extends SubTwo { @Override abstract void varargsMethod(Object... newNames); } - }""") + }\ + """) .doTest(); } @@ -430,7 +437,8 @@ abstract class SubThree extends SubTwo { @Override abstract void arrayMethod(Object[] xs); } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/PreconditionsInvalidPlaceholderTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/PreconditionsInvalidPlaceholderTest.java index 8b3ef393a36..e6d0d511f61 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/PreconditionsInvalidPlaceholderTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/PreconditionsInvalidPlaceholderTest.java @@ -59,7 +59,8 @@ public void verifyFoo(int x) { // BUG: Diagnostic contains: Verify.verify(x > 0, "%d > 0", x); } - }""") + }\ + """) .doTest(); } @@ -95,7 +96,8 @@ public static void checkNotNull(Object foo, String bar, Object baz) {} public void checkSelf() { checkNotNull(foo, "Foo", this); } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/PrimitiveArrayPassedToVarargsMethodTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/PrimitiveArrayPassedToVarargsMethodTest.java index a67618f4c03..aa15815c527 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/PrimitiveArrayPassedToVarargsMethodTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/PrimitiveArrayPassedToVarargsMethodTest.java @@ -66,7 +66,8 @@ public void doIt() { // BUG: Diagnostic contains: Arrays.asList(intArray); } - }""") + }\ + """) .doTest(); } @@ -96,7 +97,8 @@ public void doIt() { intArrayVarargsMethod(intArray); objectVarargsMethodWithMultipleParams(new Object()); } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/PrivateSecurityContractProtoAccessTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/PrivateSecurityContractProtoAccessTest.java index 7a79cb14f02..6d9516bad94 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/PrivateSecurityContractProtoAccessTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/PrivateSecurityContractProtoAccessTest.java @@ -87,7 +87,8 @@ static ByteString readSafeHtmlProtoBuilderBytes(SafeHtmlProto.Builder safeHtmlPr // BUG: Diagnostic contains: Forbidden access to a private proto field return safeHtmlProto.getPrivateDoNotAccessOrElseSafeHtmlWrappedValueBytes(); } -}""") +}\ +""") .doTest(); } @@ -115,7 +116,8 @@ public class PrivateSecurityContractProtoAccessNegativeCases { static { safeHtml = SafeHtmls.fromProto(safeHtmlProto); } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ProtocolBufferOrdinalTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ProtocolBufferOrdinalTest.java index 6c0c00ef394..20561a34d54 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ProtocolBufferOrdinalTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ProtocolBufferOrdinalTest.java @@ -67,7 +67,8 @@ public int getNumber() { return number; } } - }""") + }\ + """) .doTest(); } @@ -87,7 +88,8 @@ public class ProtocolBufferOrdinalNegativeCases { public static void checkProtoEnum() { TestEnum.TEST_ENUM_VAL.getNumber(); } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/RestrictedApiCheckerTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/RestrictedApiCheckerTest.java index 6a75bd876c6..a0e97c4d3e6 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/RestrictedApiCheckerTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/RestrictedApiCheckerTest.java @@ -46,7 +46,8 @@ protected RestrictedApiCheckerTest(Class checker) { import java.lang.annotation.Target; @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) - public @interface Allowlist {}""") + public @interface Allowlist {}\ + """) .addSourceLines( "RestrictedApiMethods.java", """ @@ -120,7 +121,8 @@ interface IFaceWithRestriction { } @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) -@interface AllowlistWithWarning {}""") +@interface AllowlistWithWarning {}\ +""") .matchAllDiagnostics(); refactoringTest = BugCheckerRefactoringTestHelper.newInstance(checker, RestrictedApiCheckerTest.class); diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/RethrowReflectiveOperationExceptionAsLinkageErrorTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/RethrowReflectiveOperationExceptionAsLinkageErrorTest.java index 6601707e09b..bf0f21f2fab 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/RethrowReflectiveOperationExceptionAsLinkageErrorTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/RethrowReflectiveOperationExceptionAsLinkageErrorTest.java @@ -81,7 +81,8 @@ void multiLineCatchBlock() { throw new AssertionError(e1); } } - }""") + }\ + """) .doTest(); } @@ -143,7 +144,8 @@ void multiCatchExceptions() { void throwNewReflectiveOperationException() { throw new AssertionError(new ReflectiveOperationException("Test")); } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ReturnValueIgnoredTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ReturnValueIgnoredTest.java index 2d573fd9f8f..2b4f1c5453a 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ReturnValueIgnoredTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ReturnValueIgnoredTest.java @@ -186,7 +186,8 @@ public class ReturnValueIgnoredPositiveCases { // BUG: Diagnostic contains: Return value of 'toString' must be used Arrays.toString(objects); } - }""") + }\ + """) .doTest(); } @@ -250,7 +251,8 @@ public void arraysNoReturnValues() { Arrays.fill(numbers, 0); Arrays.sort(numbers); } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/RxReturnValueIgnoredTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/RxReturnValueIgnoredTest.java index 455f1c1bc43..3ef52fd703d 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/RxReturnValueIgnoredTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/RxReturnValueIgnoredTest.java @@ -237,7 +237,8 @@ static void getFromMap() { // BUG: Diagnostic contains: Rx objects must be checked. map4.get(null); } -}""") +}\ +""") .doTest(); } @@ -342,7 +343,8 @@ void checkIgnore() { getFlowable(); getMaybe(); } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/SelfAssertionTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/SelfAssertionTest.java index e442fa300d5..4bc441f7b6a 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/SelfAssertionTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/SelfAssertionTest.java @@ -101,7 +101,8 @@ public void testAssertWithMessageNotSame() { // BUG: Diagnostic contains: assertWithMessage("msg").that(test).isNotSameInstanceAs(test); } - }""") + }\ + """) .doTest(); } @@ -129,7 +130,8 @@ public void testEq() { public void testNeq() { assertThat(Boolean.TRUE.toString()).isNotEqualTo(Boolean.FALSE.toString()); } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/SelfAssignmentTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/SelfAssignmentTest.java index cd665b13e5f..26eca86152e 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/SelfAssignmentTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/SelfAssignmentTest.java @@ -92,7 +92,8 @@ public void testCast(int x) { // BUG: Diagnostic contains: this.a = (int) x; this.a = (int) a; } - }""") + }\ + """) .doTest(); } @@ -203,7 +204,8 @@ private static class Foobar { Foo foo; Bar bar; } - }""") + }\ + """) .doTest(); } @@ -305,7 +307,8 @@ public static int[] getIntArr() { return new int[10]; } } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/SelfComparisonTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/SelfComparisonTest.java index 4867362da1e..f698cf4074e 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/SelfComparisonTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/SelfComparisonTest.java @@ -120,7 +120,8 @@ public int test5() { return compareTo(this); } } - }""") + }\ + """) .doTest(); } @@ -167,7 +168,8 @@ public int compareTo(CopmarisonTest obj) { return testField.compareTo(obj.testField); } } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/SelfEqualsTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/SelfEqualsTest.java index 3b403c90409..121bd114eca 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/SelfEqualsTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/SelfEqualsTest.java @@ -135,7 +135,8 @@ public void testSub() { // BUG: Diagnostic contains: sc.equals(sc); } - }""") + }\ + """) .doTest(); } @@ -184,7 +185,8 @@ public void testAssertThatEq(SelfEqualsNegativeCases obj) { public void testAssertThatNeq(SelfEqualsNegativeCases obj) { assertThat(obj).isNotEqualTo(obj); } - }""") + }\ + """) .doTest(); } @@ -259,7 +261,8 @@ private static class ForTesting { public ForTesting testing; public String string; } - }""") + }\ + """) .doTest(); } @@ -296,7 +299,8 @@ public boolean equals(Object o) { public int hashCode() { return field != null ? field.hashCode() : 0; } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ShouldHaveEvenArgsTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ShouldHaveEvenArgsTest.java index ae60d79438b..15d8a9955ee 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ShouldHaveEvenArgsTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ShouldHaveEvenArgsTest.java @@ -90,7 +90,8 @@ public void testWithOddArgsWithCorrespondence() { // BUG: Diagnostic contains: even number of arguments .containsExactly("hello", "there", "hello", "there", "rest"); } - }""") + }\ + """) .doTest(); } @@ -145,7 +146,8 @@ public void testWithArray() { assertThat(map).containsExactly(key, value, (Object[]) args); assertThat(map).containsExactly(key, value, key, value, key, value); } - }""") + }\ + """) .doTest(); } @@ -204,7 +206,8 @@ public void testWithOddArgsWithCorrespondence() { // BUG: Diagnostic contains: even number of arguments .containsExactly("hello", "there", "hello", "there", "rest"); } - }""") + }\ + """) .doTest(); } @@ -256,7 +259,8 @@ public void testWithArray() { assertThat(multimap).containsExactly(key, value, (Object[]) args); assertThat(multimap).containsExactly(key, value, key, value, key, value); } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/SizeGreaterThanOrEqualsZeroTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/SizeGreaterThanOrEqualsZeroTest.java index b3b8b28fcff..b681db4532b 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/SizeGreaterThanOrEqualsZeroTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/SizeGreaterThanOrEqualsZeroTest.java @@ -179,7 +179,8 @@ List getIntList() { return intList; } } -}""") +}\ +""") .doTest(); } @@ -271,7 +272,8 @@ public int size() { return length; } } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/StaticQualifiedUsingExpressionTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/StaticQualifiedUsingExpressionTest.java index 515d4c46cc2..62f864ff9bb 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/StaticQualifiedUsingExpressionTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/StaticQualifiedUsingExpressionTest.java @@ -199,7 +199,8 @@ public void test7() { // x = C.foo(); int x = new C().foo(); } - }""") + }\ + """) .doTest(); } @@ -227,7 +228,8 @@ public int test1() { // return TestClass.staticTestMethod() return new TestClass().staticTestMethod(); } - }""") + }\ + """) .doTest(); } @@ -278,7 +280,8 @@ public void testJavacAltname() { public void testEclipseAltname() { this.staticTestMethod(); } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/StringBuilderInitWithCharTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/StringBuilderInitWithCharTest.java index 98e894e35ef..f4468b6c04b 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/StringBuilderInitWithCharTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/StringBuilderInitWithCharTest.java @@ -51,7 +51,8 @@ public class StringBuilderInitWithCharPositiveCases { // BUG: Diagnostic contains: new StringBuilder().append(c) new StringBuilder(c); } - }""") + }\ + """) .doTest(); } @@ -72,7 +73,8 @@ public class StringBuilderInitWithCharNegativeCases { new StringBuilder(5); new StringBuilder(); } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/StringSplitterTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/StringSplitterTest.java index 3f74ecbcb38..cc0ab07f89a 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/StringSplitterTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/StringSplitterTest.java @@ -503,7 +503,8 @@ public void StringSplitOneArg() { // BUG: Diagnostic contains: String[] xs = foo.split(":"); } - }""") + }\ + """) .doTest(); } @@ -530,7 +531,8 @@ public void StringSplitTwoArgsOneNegative() { String foo = "a:b"; foo.split(":", -1); } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/SuppressWarningsDeprecatedTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/SuppressWarningsDeprecatedTest.java index c8883d8c658..da18dc2218d 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/SuppressWarningsDeprecatedTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/SuppressWarningsDeprecatedTest.java @@ -107,7 +107,8 @@ public static void positiveCase8() {} // BUG: Diagnostic contains: @SuppressWarnings(value = "deprecation") @SuppressWarnings(value = "deprecated") public static void positiveCase9() {} - }""") + }\ + """) .doTest(); } @@ -152,7 +153,8 @@ public static void negativeCase6() { class Bar {} Bar b = null; } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/SwigMemoryLeakTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/SwigMemoryLeakTest.java index 291ae69433c..57731616977 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/SwigMemoryLeakTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/SwigMemoryLeakTest.java @@ -61,7 +61,8 @@ public synchronized void delete() { swigCPtr = 0; } } -}""") +}\ +""") .doTest(); } @@ -101,7 +102,8 @@ public synchronized void delete() { } private static native void nativeDelete(long cptr); - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ThreadJoinLoopTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ThreadJoinLoopTest.java index d7fa779c8da..c2deeb2cc93 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ThreadJoinLoopTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ThreadJoinLoopTest.java @@ -205,7 +205,8 @@ public void whileInThread() { } } } - }""") + }\ + """) .doTest(); } @@ -334,7 +335,8 @@ public void tryAssigningThread(Thread thread) { } } } - }""") + }\ + """) .doTest(); } @@ -512,7 +514,8 @@ public void whileInThread() { } } } - }""") + }\ + """) .addOutputLines( "ThreadJoinLoopPositiveCases_expected.java", """ @@ -592,7 +595,8 @@ public void whileInThread() { Uninterruptibles.joinUninterruptibly(this); } } - }""") + }\ + """) .doTest(TestMode.AST_MATCH); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ThrowIfUncheckedKnownCheckedTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ThrowIfUncheckedKnownCheckedTest.java index 10594f8b635..3adf6cd21bd 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ThrowIfUncheckedKnownCheckedTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ThrowIfUncheckedKnownCheckedTest.java @@ -71,7 +71,8 @@ void checkedGeneric(E e) { } void foo() throws IOException, ExecutionException {} - }""") + }\ + """) .doTest(); } @@ -146,7 +147,8 @@ void nullException() { throwIfUnchecked(null); // throws NPE propagateIfPossible(null); // no-op } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ThrowsUncheckedExceptionTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ThrowsUncheckedExceptionTest.java index 3d46649513f..cc00e49be0d 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ThrowsUncheckedExceptionTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ThrowsUncheckedExceptionTest.java @@ -69,7 +69,8 @@ public void doEverything() throws RuntimeException, IOException, IndexOutOfBound public void doBetter() throws RuntimeException, AssertionError { throw new RuntimeException("thrown"); } -}""") +}\ +""") .doTest(); } @@ -95,7 +96,8 @@ public void doSomething() { public void doMore() throws IOException { throw new FileNotFoundException("thrown"); } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/TreeToStringTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/TreeToStringTest.java index 53510d5ccec..109a5f3e660 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/TreeToStringTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/TreeToStringTest.java @@ -151,7 +151,8 @@ public boolean matches(ClassTree classTree, VisitorState state) { } }; } -}""") +}\ +""") .doTest(); } @@ -179,7 +180,8 @@ private static void foo(VisitorState state) { ASTHelpers.getSymbol(tree).getSimpleName().toString(); } } - }""") + }\ + """) .addModules( "jdk.compiler/com.sun.tools.javac.code", "jdk.compiler/com.sun.tools.javac.util") .doTest(); diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/TruthAssertExpectedTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/TruthAssertExpectedTest.java index 75836afb144..42affb6a947 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/TruthAssertExpectedTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/TruthAssertExpectedTest.java @@ -86,7 +86,8 @@ private void lists() { // assertThat(ImmutableList.of(this)).containsExactlyElementsIn(EXPECTED_LIST).inOrder(); assertThat(EXPECTED_LIST).containsExactlyElementsIn(ImmutableList.of(this)).inOrder(); } -}""") +}\ +""") .doTest(); } @@ -146,7 +147,8 @@ private void constantValues() { assertThat(expected).isEqualTo(10L); assertThat(expected).isEqualTo(CONSTANT); } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/TruthConstantAssertsTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/TruthConstantAssertsTest.java index 0df28772544..a0769197a4c 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/TruthConstantAssertsTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/TruthConstantAssertsTest.java @@ -77,7 +77,8 @@ private static TruthConstantAssertsPositiveCases someStaticMethod() { private TruthConstantAssertsPositiveCases memberMethod() { return new TruthConstantAssertsPositiveCases(); } -}""") +}\ +""") .doTest(); } @@ -109,7 +110,8 @@ public void testNegativeCases() { private static TruthConstantAssertsNegativeCases getObject() { return new TruthConstantAssertsNegativeCases(); } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/TryFailThrowableTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/TryFailThrowableTest.java index 49aa017ca8e..a26ab6e191c 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/TryFailThrowableTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/TryFailThrowableTest.java @@ -216,7 +216,8 @@ public static void catchesError_nestedNoBlock() { } catch (Error e) { } } -}""") +}\ +""") .doTest(); } @@ -395,7 +396,8 @@ public void testInTestCase() { private static void dummyRecover() {} private static void dummyMethod() {} - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/URLEqualsHashCodeTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/URLEqualsHashCodeTest.java index e10854a020e..e04a6186a25 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/URLEqualsHashCodeTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/URLEqualsHashCodeTest.java @@ -137,7 +137,8 @@ public void immutableSetOfURL() { // BUG: Diagnostic contains: java.net.URL ImmutableSet urlSet2 = ImmutableSet.builder().build(); } - }""") + }\ + """) .doTest(); } @@ -203,7 +204,8 @@ private static class ExtendedMap extends HashMap { public void hashMapExtendedClass() { ExtendedMap urlMap; } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/UngroupedOverloadsTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/UngroupedOverloadsTest.java index d40c6dd8d15..862c467df6c 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/UngroupedOverloadsTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/UngroupedOverloadsTest.java @@ -80,7 +80,8 @@ public void foo(int x, int y) { } public void norf() {} - }""") + }\ + """) .doTest(); } @@ -166,7 +167,8 @@ public void foo() { public void norf(int x, int y, int w) { norf(x + w, y + w); } - }""") + }\ + """) .doTest(); } @@ -221,7 +223,8 @@ public void foo(int x) {} public void foo() { foo(foo); } - }""") + }\ + """) .doTest(); } @@ -275,7 +278,8 @@ public void quux(int x) { public void foo() { foo(42); } - }""") + }\ + """) .doTest(); } @@ -324,7 +328,8 @@ public void quux(int x) { public void foo() { foo(42); } -}""") +}\ +""") .setArgs(ImmutableList.of("-XepOpt:UngroupedOverloads:BatchFindings")) .doTest(); } @@ -375,7 +380,8 @@ public void baz(String x, String y) { public int foo() { return this.foo; } - }""") + }\ + """) .doTest(); } @@ -414,7 +420,8 @@ public void bar(int x, int y, int z) { public void quux() {} public void bar(String s) {} - }""") + }\ + """) .addOutputLines( "UngroupedOverloadsRefactoringComments_expected.java", """ @@ -447,7 +454,8 @@ public void bar(String s) {} public static final String BAZ = "baz"; // Stuff about `baz` continues. public void quux() {} - }""") + }\ + """) .doTest(); } @@ -494,7 +502,8 @@ public void norf() {} public void quux(int x, int y, int z) {} public void thud() {} - }""") + }\ + """) .addOutputLines( "UngroupedOverloadsRefactoringMultiple_expected.java", """ @@ -535,7 +544,8 @@ public void quux(int x, int y, int z) {} public void norf() {} public void thud() {} - }""") + }\ + """) .doTest(); } @@ -577,7 +587,8 @@ public void quux(int x, int y) {} public void foo(int x, int y, int z) {} public void bar(int x, int y) {} - }""") + }\ + """) .addOutputLines( "UngroupedOverloadsRefactoringInterleaved_expected.java", """ @@ -613,7 +624,8 @@ public void quux() {} public void quux(int x) {} public void quux(int x, int y) {} - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryBoxedAssignmentTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryBoxedAssignmentTest.java index 5152e81965d..836ddfa058a 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryBoxedAssignmentTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryBoxedAssignmentTest.java @@ -103,7 +103,8 @@ Integer positive_wrappedAgain(int aInteger) { void negative_methodReference() { Function toBoolean = Boolean::valueOf; } - }""") + }\ + """) .addOutputLines( "UnnecessaryBoxedAssignmentCases_expected.java", """ @@ -175,7 +176,8 @@ Integer positive_wrappedAgain(int aInteger) { void negative_methodReference() { Function toBoolean = Boolean::valueOf; } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryBoxedVariableTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryBoxedVariableTest.java index c8b1eeb04ce..74c5212ed8e 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryBoxedVariableTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryBoxedVariableTest.java @@ -237,7 +237,8 @@ private void methodPrimitiveArg(int i) {} private Integer methodBoxedArg(Integer i) { return i; } - }""") + }\ + """) .addOutputLines( "UnnecessaryBoxedVariableCases_expected.java", """ @@ -435,7 +436,8 @@ private void methodPrimitiveArg(int i) {} private Integer methodBoxedArg(Integer i) { return i; } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryLongToIntConversionTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryLongToIntConversionTest.java index 9c34f79ecd8..e60a3c4fc70 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryLongToIntConversionTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryLongToIntConversionTest.java @@ -103,7 +103,8 @@ public void intValue() { // BUG: Diagnostic contains: UnnecessaryLongToIntConversion acceptsLong(x.intValue()); } -}""") +}\ +""") .doTest(); } @@ -218,7 +219,8 @@ public void toIntExactForIntParameter() { long x = 1; acceptsInt(Math.toIntExact(x)); } -}""") +}\ +""") .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/UnsafeReflectiveConstructionCastTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/UnsafeReflectiveConstructionCastTest.java index aae527bdfcc..ae434e4e93f 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/UnsafeReflectiveConstructionCastTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/UnsafeReflectiveConstructionCastTest.java @@ -180,7 +180,8 @@ public T get(String className) { } } } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/WaitNotInLoopTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/WaitNotInLoopTest.java index fc300957034..6a5a14c29e2 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/WaitNotInLoopTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/WaitNotInLoopTest.java @@ -110,7 +110,8 @@ public void testAwaitUntil(Condition cond) throws Exception { // BUG: Diagnostic contains: awaitUntil(java.util.Date) must always be called in a loop cond.awaitUntil(new Date()); } -}""") +}\ +""") .doTest(); } @@ -214,7 +215,8 @@ private void wait(Object obj) {} public void testNotObjectWait() { wait(new Object()); } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/android/BinderIdentityRestoredDangerouslyTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/android/BinderIdentityRestoredDangerouslyTest.java index da963d9a162..8116775f42d 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/android/BinderIdentityRestoredDangerouslyTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/android/BinderIdentityRestoredDangerouslyTest.java @@ -41,7 +41,8 @@ public static final long clearCallingIdentity() { } public static final void restoreCallingIdentity(long token) {} - }""") + }\ + """) .setArgs(ImmutableList.of("-XDandroidCompatible=true")); @Test diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/android/FragmentInjectionTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/android/FragmentInjectionTest.java index ade90eeffe6..0ce68ef4a83 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/android/FragmentInjectionTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/android/FragmentInjectionTest.java @@ -40,7 +40,8 @@ public class PreferenceActivity { protected boolean isValidFragment(String className) { return true; } - }""") + }\ + """) .setArgs(ImmutableList.of("-XDandroidCompatible=true")); @Test diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/android/FragmentNotInstantiableTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/android/FragmentNotInstantiableTest.java index 2ddc85e10d7..a53d878403b 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/android/FragmentNotInstantiableTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/android/FragmentNotInstantiableTest.java @@ -117,7 +117,8 @@ class LocalFragment extends Fragment {} return new LocalFragment(); } } - }""") + }\ + """) .doTest(); } @@ -202,7 +203,8 @@ public class ImplicitlyStaticInnerFragment extends Fragment {} class ImplicitlyStaticAndPublicInnerFragment extends Fragment {} } - }""") + }\ + """) .doTest(); } @@ -280,7 +282,8 @@ class LocalFragment extends Fragment {} return new LocalFragment(); } } - }""") + }\ + """) .addSourceLines( "CustomFragment.java", """ @@ -289,7 +292,8 @@ class LocalFragment extends Fragment {} /** * @author jasonlong@google.com (Jason Long) */ - public class CustomFragment {}""") + public class CustomFragment {}\ + """) .addSourceLines( "CustomFragmentNotInstantiablePositiveCases.java", """ @@ -354,7 +358,8 @@ class LocalFragment extends CustomFragment {} return new LocalFragment(); } } - }""") + }\ + """) .doTest(); } @@ -439,7 +444,8 @@ public class ImplicitlyStaticInnerFragment extends Fragment {} class ImplicitlyStaticAndPublicInnerFragment extends Fragment {} } - }""") + }\ + """) .addSourceLines( "CustomFragment.java", """ @@ -448,7 +454,8 @@ class ImplicitlyStaticAndPublicInnerFragment extends Fragment {} /** * @author jasonlong@google.com (Jason Long) */ - public class CustomFragment {}""") + public class CustomFragment {}\ + """) .addSourceLines( "CustomFragmentNotInstantiableNegativeCases.java", """ @@ -507,7 +514,8 @@ public class ImplicitlyStaticInnerFragment extends CustomFragment {} class ImplicitlyStaticAndPublicInnerFragment extends CustomFragment {} } - }""") + }\ + """) .doTest(); } @@ -519,13 +527,15 @@ private CompilationTestHelper createCompilationTestHelper( """ package android.app; - public class Fragment {}""") + public class Fragment {}\ + """) .addSourceLines( "Fragment.java", """ package android.support.v4.app; - public class Fragment {}""") + public class Fragment {}\ + """) .setArgs(ImmutableList.of("-XDandroidCompatible=true")); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/android/HardCodedSdCardPathTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/android/HardCodedSdCardPathTest.java index 11042158b9b..46f2f391e83 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/android/HardCodedSdCardPathTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/android/HardCodedSdCardPathTest.java @@ -79,7 +79,8 @@ public class HardCodedSdCardPathPositiveCases { // BUG: Diagnostic contains: Context static final String PATH11 = "/data" + "/" + "user"; - }""") + }\ + """) .doTest(); } @@ -127,7 +128,8 @@ public class HardCodedSdCardPathNegativeCases { static final String FRAGMENT4 = "1user"; static final String PATH5 = FRAGMENT3 + "/" + FRAGMENT4; - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/android/IsLoggableTagLengthTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/android/IsLoggableTagLengthTest.java index 78d2d551b33..6242eb38635 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/android/IsLoggableTagLengthTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/android/IsLoggableTagLengthTest.java @@ -41,7 +41,8 @@ public static boolean isLoggable(String tag, int level) { } public static final int INFO = 0; - }""") + }\ + """) .setArgs(ImmutableList.of("-XDandroidCompatible=true")); @Test diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/android/MislabeledAndroidStringTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/android/MislabeledAndroidStringTest.java index fe744b8c58a..25ae3c9f630 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/android/MislabeledAndroidStringTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/android/MislabeledAndroidStringTest.java @@ -133,7 +133,8 @@ public static final class string { public static final int no = 1; public static final int copy = 2; } - }""") + }\ + """) .setArgs(ImmutableList.of("-XDandroidCompatible=true")); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/android/RectIntersectReturnValueIgnoredTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/android/RectIntersectReturnValueIgnoredTest.java index e75af23159b..2bc89234c8e 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/android/RectIntersectReturnValueIgnoredTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/android/RectIntersectReturnValueIgnoredTest.java @@ -44,7 +44,8 @@ public boolean intersect(Rect other) { } public void setEmpty() {} - }""") + }\ + """) .setArgs(ImmutableList.of("-XDandroidCompatible=true")); @Test @@ -93,7 +94,8 @@ void checkInField(RectContainer container) { container.rect.intersect( container.xPos, container.yPos, container.xPos + 10, container.yPos + 20); } -}""") +}\ +""") .doTest(); } @@ -156,7 +158,8 @@ void checkInMethod(int length, int width) { RectContainer container = new RectContainer(); container.intersect(length, width); } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/android/WakelockReleasedDangerouslyTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/android/WakelockReleasedDangerouslyTest.java index 28f4ce8c46c..56e7f68a331 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/android/WakelockReleasedDangerouslyTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/android/WakelockReleasedDangerouslyTest.java @@ -51,7 +51,8 @@ public void release() {} public void setReferenceCounted(boolean referenceCounted) {} } - }""") + }\ + """) .expectUnchanged(); private final CompilationTestHelper compilationHelper = CompilationTestHelper.newInstance(WakelockReleasedDangerously.class, getClass()) @@ -74,7 +75,8 @@ public void release() {} public void setReferenceCounted(boolean referenceCounted) {} } - }""") + }\ + """) .setArgs(ImmutableList.of("-XDandroidCompatible=true")); @Test diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/collectionincompatibletype/CollectionIncompatibleTypeTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/collectionincompatibletype/CollectionIncompatibleTypeTest.java index 18f0bde8092..46116afe447 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/collectionincompatibletype/CollectionIncompatibleTypeTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/collectionincompatibletype/CollectionIncompatibleTypeTest.java @@ -292,7 +292,8 @@ public boolean oneFinalClassAndOneNonFinalClass( // BUG: Diagnostic contains: return collection.contains(nonFinalClass1); } -}""") +}\ +""") .doTest(); } @@ -567,7 +568,8 @@ public void classToken( Set>> iterables, Class arrayListClass) { iterables.contains(arrayListClass); } -}""") +}\ +""") .doTest(); } @@ -587,7 +589,8 @@ public void test() { Properties properties = new Properties(); properties.get(""); } - }""") + }\ + """) .doTest(); } @@ -606,7 +609,8 @@ public class CollectionIncompatibleTypeClassCast extends HashMap { public void test(K k) { get(k); } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/collectionincompatibletype/IncompatibleArgumentTypeTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/collectionincompatibletype/IncompatibleArgumentTypeTest.java index b685033f07a..9fcf7d60bf0 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/collectionincompatibletype/IncompatibleArgumentTypeTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/collectionincompatibletype/IncompatibleArgumentTypeTest.java @@ -81,7 +81,8 @@ void testVarargs(A stringA) { // OK, everything compatible w/ Object Object o = stringA.varargs("foo", 2L, 1.0d, "a"); } -}""") +}\ +""") .doTest(); } @@ -155,7 +156,8 @@ void extraStuff() { // enforce it here. new Foo().new Sub().new SubSub().>methodVarIsFree(123); } -}""") +}\ +""") .doTest(); } @@ -234,7 +236,8 @@ void testVarArgs(Multimap intToString) { Integer[] keys = {123, 345}; intToString.containsAllKeys(123, (Object[]) keys); } -}""") +}\ +""") .doTest(); } @@ -293,7 +296,8 @@ void testArraySpecialization( // BUG: Diagnostic contains: String[] is not compatible with the required type: Number[] arrayTest.doSomething(strings); } -}""") +}\ +""") .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/flogger/FloggerRedundantIsEnabledTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/flogger/FloggerRedundantIsEnabledTest.java index c3295101e82..85ca8761f5d 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/flogger/FloggerRedundantIsEnabledTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/flogger/FloggerRedundantIsEnabledTest.java @@ -137,7 +137,8 @@ public void checkSevere(FluentLogger logger) { logger.atSevere().log("test"); } } - }""") + }\ + """) .doTest(); } @@ -232,7 +233,8 @@ public boolean isEnabled() { return true; } } -}""") +}\ +""") .doTest(); } @@ -341,7 +343,8 @@ public void checkSevere(FluentLogger logger) { logger.atSevere().log("test"); } } - }""") + }\ + """) .addOutputLines( "FloggerRedundantIsEnabledPositiveCases_expected.java", """ @@ -415,7 +418,8 @@ public void checkWarning(FluentLogger logger) { public void checkSevere(FluentLogger logger) { logger.atSevere().log("test"); } - }""") + }\ + """) .doTest(TestMode.AST_MATCH); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/AssistedInjectAndInjectOnConstructorsTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/AssistedInjectAndInjectOnConstructorsTest.java index ae7a671583b..eaad33b1b8c 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/AssistedInjectAndInjectOnConstructorsTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/AssistedInjectAndInjectOnConstructorsTest.java @@ -84,7 +84,8 @@ public TestClass3(int n) {} public TestClass3(String s) {} } -}""") +}\ +""") .doTest(); } @@ -145,7 +146,8 @@ public TestClass6() {} @AssistedInject public TestClass6(int n) {} } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/AssistedInjectAndInjectOnSameConstructorTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/AssistedInjectAndInjectOnSameConstructorTest.java index b0aa1b95a74..2d33e3bf6f8 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/AssistedInjectAndInjectOnSameConstructorTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/AssistedInjectAndInjectOnSameConstructorTest.java @@ -61,7 +61,8 @@ public class TestClass2 { @AssistedInject public TestClass2() {} } -}""") +}\ +""") .doTest(); } @@ -141,7 +142,8 @@ public class TestClass8 { @AssistedInject public TestClass8() {} } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/AutoFactoryAtInjectTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/AutoFactoryAtInjectTest.java index 471f873e928..2dbb1abf9f6 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/AutoFactoryAtInjectTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/AutoFactoryAtInjectTest.java @@ -63,7 +63,8 @@ static class HasAutoFactoryOnConstructor { @AutoFactory HasAutoFactoryOnConstructor() {} } - }""") + }\ + """) .doTest(); } @@ -103,7 +104,8 @@ static class OnDifferentConstructors { @AutoFactory OnDifferentConstructors(Object object) {} } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/CloseableProvidesTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/CloseableProvidesTest.java index 2e366812005..49a64f0663f 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/CloseableProvidesTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/CloseableProvidesTest.java @@ -67,7 +67,8 @@ ImplementsClosable providesImplementsClosable() { PrintWriter providesPrintWriter() throws Exception { return new PrintWriter("some_file_path", StandardCharsets.UTF_8.name()); } - }""") + }\ + """) .doTest(); } @@ -103,7 +104,8 @@ DoesNotImplementsClosable providesDoesNotImplementsClosable() { Object providesObject() { return new Object(); } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/InjectOnMemberAndConstructorTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/InjectOnMemberAndConstructorTest.java index 0cb41dabbdf..a0bb7409a83 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/InjectOnMemberAndConstructorTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/InjectOnMemberAndConstructorTest.java @@ -113,7 +113,8 @@ public class MixedInject { @Inject public MixedInject() {} } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/InjectedConstructorAnnotationsTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/InjectedConstructorAnnotationsTest.java index 1b966c9a261..cbe90d5dd1b 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/InjectedConstructorAnnotationsTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/InjectedConstructorAnnotationsTest.java @@ -64,7 +64,8 @@ public class TestClass3 { // BUG: Diagnostic contains: @Inject public TestClass3 @TestBindingAnnotation @Inject(optional = true) public TestClass3() {} } - }""") + }\ + """) .doTest(); } @@ -110,7 +111,8 @@ public class TestClass4 { @TestAnnotation public TestClass4() {} } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/InvalidTargetingOnScopingAnnotationTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/InvalidTargetingOnScopingAnnotationTest.java index ceeaf68d6f0..2fce2bbb0c9 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/InvalidTargetingOnScopingAnnotationTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/InvalidTargetingOnScopingAnnotationTest.java @@ -96,7 +96,8 @@ public class InvalidTargetingOnScopingAnnotationPositiveCases { @ScopeAnnotation @Retention(RUNTIME) public @interface TestAnnotation7 {} - }""") + }\ + """) .doTest(); } @@ -145,7 +146,8 @@ public class InvalidTargetingOnScopingAnnotationNegativeCases { @Target(PARAMETER) @Retention(RUNTIME) public @interface TestAnnotation4 {} -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/JavaxInjectOnAbstractMethodTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/JavaxInjectOnAbstractMethodTest.java index 98165d4c82d..bb7396c4295 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/JavaxInjectOnAbstractMethodTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/JavaxInjectOnAbstractMethodTest.java @@ -99,7 +99,8 @@ interface HasDefault { @javax.inject.Inject default void foo() {} } -}""") +}\ +""") .doTest(); } @@ -155,7 +156,8 @@ public abstract class TestClass6 { @javax.inject.Inject abstract void abstractMethod(); } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/JavaxInjectOnFinalFieldTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/JavaxInjectOnFinalFieldTest.java index 561476448fc..6a07ffb71c9 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/JavaxInjectOnFinalFieldTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/JavaxInjectOnFinalFieldTest.java @@ -52,7 +52,8 @@ public class TestClass1 { @Inject public final int n = 0; } - }""") + }\ + """) .doTest(); } @@ -89,7 +90,8 @@ public class TestClass4 { @Inject final void method() {} } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/MissingRuntimeRetentionTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/MissingRuntimeRetentionTest.java index 0b7daeb5dc6..1bbe9927fd5 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/MissingRuntimeRetentionTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/MissingRuntimeRetentionTest.java @@ -103,7 +103,8 @@ public class MissingRuntimeRetentionPositiveCases { @Target({TYPE, METHOD}) // BUG: Diagnostic contains: @Retention(RUNTIME) public @interface TestAnnotation7 {} - }""") + }\ + """) .doTest(); } @@ -168,7 +169,8 @@ public class MissingRuntimeRetentionNegativeCases { @com.google.inject.multibindings.MapKey @Retention(RUNTIME) public @interface TestAnnotation7 {} - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/MoreThanOneInjectableConstructorTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/MoreThanOneInjectableConstructorTest.java index 39d90192e69..d11ddde4062 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/MoreThanOneInjectableConstructorTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/MoreThanOneInjectableConstructorTest.java @@ -94,7 +94,8 @@ public TestClass4(int m, int n) {} @Inject public TestClass4(int m, int n, boolean x) {} } -}""") +}\ +""") .doTest(); } @@ -172,7 +173,8 @@ public TestClass7() {} @Inject public TestClass7(int n) {} } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/MoreThanOneQualifierTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/MoreThanOneQualifierTest.java index b3fe88213cc..e47426cf7f1 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/MoreThanOneQualifierTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/MoreThanOneQualifierTest.java @@ -165,7 +165,8 @@ public void setN( @BindingAnnotation @Retention(RUNTIME) public @interface Bar2 {} -}""") +}\ +""") .doTest(); } @@ -233,7 +234,8 @@ public void setN(@Bar int n) {} @BindingAnnotation @Retention(RUNTIME) public @interface Bar {} -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/MoreThanOneScopeAnnotationOnClassTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/MoreThanOneScopeAnnotationOnClassTest.java index c95f88568f9..29d63eb26a3 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/MoreThanOneScopeAnnotationOnClassTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/MoreThanOneScopeAnnotationOnClassTest.java @@ -67,7 +67,8 @@ class TestClass2 {} @SessionScoped // BUG: Diagnostic contains: class TestClass3 {} - }""") + }\ + """) .doTest(); } @@ -145,7 +146,8 @@ public class DaggerProductionSubcomponent {} /** Suppression through secondary name */ @SuppressWarnings("MoreThanOneScopeAnnotationOnClass") public class TestClass6 {} -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/OverlappingQualifierAndScopeAnnotationTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/OverlappingQualifierAndScopeAnnotationTest.java index 85f3fd57009..e028c6d0ca5 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/OverlappingQualifierAndScopeAnnotationTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/OverlappingQualifierAndScopeAnnotationTest.java @@ -62,7 +62,8 @@ public class OverlappingQualifierAndScopeAnnotationPositiveCases { @com.google.inject.BindingAnnotation // BUG: Diagnostic contains: OverlappingQualifierAndScopeAnnotation @interface JavaxScopeAndGuiceBindingAnnotation {} - }""") + }\ + """) .doTest(); } @@ -111,7 +112,8 @@ public class OverlappingQualifierAndScopeAnnotationNegativeCases { @javax.inject.Scope @com.google.inject.BindingAnnotation @interface JavaxScopeAndGuiceBindingAnnotation {} - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/QualifierWithTypeUseTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/QualifierWithTypeUseTest.java index 37aae2df01b..7b90ba4a1e9 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/QualifierWithTypeUseTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/QualifierWithTypeUseTest.java @@ -70,7 +70,8 @@ public class QualifierWithTypeUsePositiveCases { // BUG: Diagnostic contains: remove @Target(ElementType.TYPE_USE) @interface BindingAnnotation3 {} - }""") + }\ + """) .doTest(); } @@ -95,7 +96,8 @@ public class QualifierWithTypeUseNegativeCases { @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface NotAQualifier {} - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/ScopeAnnotationOnInterfaceOrAbstractClassTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/ScopeAnnotationOnInterfaceOrAbstractClassTest.java index 2929c632eb0..67519b6627a 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/ScopeAnnotationOnInterfaceOrAbstractClassTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/ScopeAnnotationOnInterfaceOrAbstractClassTest.java @@ -58,7 +58,8 @@ public abstract class TestClass1 {} // BUG: Diagnostic contains: remove @Singleton public interface TestClass2 {} -}""") +}\ +""") .doTest(); } @@ -109,7 +110,8 @@ interface DaggerInterfaceComponent { @CustomScope abstract class DaggerAbstractClassSubcomponent {} } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/dagger/AndroidInjectionBeforeSuperTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/dagger/AndroidInjectionBeforeSuperTest.java index e0270ea3b43..7bd13336477 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/dagger/AndroidInjectionBeforeSuperTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/dagger/AndroidInjectionBeforeSuperTest.java @@ -34,7 +34,8 @@ public final class AndroidInjectionBeforeSuperTest { public class Activity { public void onCreate(android.os.Bundle bundle) {} - }""") + }\ + """) .addSourceLines( "Fragment.java", """ @@ -44,7 +45,8 @@ public class Fragment { public void onAttach(android.app.Activity activity) {} public void onAttach(android.content.Context context) {} - }""") + }\ + """) .addSourceLines( "Service.java", """ @@ -56,31 +58,36 @@ public void onCreate() {} public android.os.IBinder onBind(android.content.Intent intent) { return null; } - }""") + }\ + """) .addSourceLines( "Context.java", """ package android.content; - public class Context {}""") + public class Context {}\ + """) .addSourceLines( "Intent.java", """ package android.content; - public class Intent {}""") + public class Intent {}\ + """) .addSourceLines( "Bundle.java", """ package android.os; - public class Bundle {}""") + public class Bundle {}\ + """) .addSourceLines( "IBinder.java", """ package android.os; - public interface IBinder {}"""); + public interface IBinder {}\ + """); @Test public void positiveCase() { @@ -161,7 +168,8 @@ public IBinder onBind(Intent intent) { return null; } } - }""") + }\ + """) .addSourceLines( "AndroidInjection.java", """ @@ -181,7 +189,8 @@ public static void inject(Activity activity) {} public static void inject(Fragment fragment) {} public static void inject(Service service) {} -}""") +}\ +""") .doTest(); } @@ -269,7 +278,8 @@ public IBinder onBind(Intent intent) { return null; } } - }""") + }\ + """) .addSourceLines( "AndroidInjection.java", """ @@ -289,7 +299,8 @@ public static void inject(Activity activity) {} public static void inject(Fragment fragment) {} public static void inject(Service service) {} -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/AssistedInjectScopingTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/AssistedInjectScopingTest.java index 3082e263b79..84fe8ae62d3 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/AssistedInjectScopingTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/AssistedInjectScopingTest.java @@ -101,7 +101,8 @@ public class TestClass6 { @javax.inject.Inject public TestClass6(String unassisted, @Assisted String assisted) {} } - }""") + }\ + """) .doTest(); } @@ -202,7 +203,8 @@ public TestClass10(@Assisted String assisted, int i) {} public TestClass10(int i, @Assisted String assisted) {} } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/AssistedParametersTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/AssistedParametersTest.java index 25b40b11503..cede5b72f77 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/AssistedParametersTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/AssistedParametersTest.java @@ -93,7 +93,8 @@ class GenericClass { // BUG: Diagnostic contains: int: a, b GenericClass(@Assisted Integer a, @Assisted int b) {} } -}""") +}\ +""") .doTest(); } @@ -156,7 +157,8 @@ public class TestClass5 { public TestClass5( @Assisted("foo") List x, @Assisted("foo") List y, String z) {} } -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/BindingToUnqualifiedCommonTypeTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/BindingToUnqualifiedCommonTypeTest.java index 6563b1a7613..182e16500c1 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/BindingToUnqualifiedCommonTypeTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/BindingToUnqualifiedCommonTypeTest.java @@ -78,7 +78,8 @@ String providesGreeting() { return "hi"; } } - }""") + }\ + """) .doTest(); } @@ -170,7 +171,8 @@ class A {} @BindingAnnotation @Retention(RetentionPolicy.RUNTIME) @interface MyBindingAnnotation {} -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/InjectOnFinalFieldTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/InjectOnFinalFieldTest.java index 444b1ebb0d4..f4a66866850 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/InjectOnFinalFieldTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/InjectOnFinalFieldTest.java @@ -57,7 +57,8 @@ public class TestClass1 { // BUG: Diagnostic contains: Object c final Object c = null; } - }""") + }\ + """) .doTest(); } @@ -94,7 +95,8 @@ public class TestClass4 { @Inject final void method() {} } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/OverridesGuiceInjectableMethodTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/OverridesGuiceInjectableMethodTest.java index 340f0acaffe..ee89b61d971 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/OverridesGuiceInjectableMethodTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/OverridesGuiceInjectableMethodTest.java @@ -97,7 +97,8 @@ public class TestClass7 extends TestClass1 { // BUG: Diagnostic contains: @Inject public void foo() {} } -}""") +}\ +""") .doTest(); } @@ -165,7 +166,8 @@ public void foo() {} /** Class that extends a class with an injected method, but doesn't override it. */ public class TestClass7 extends TestClass1 {} -}""") +}\ +""") .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/OverridesJavaxInjectableMethodTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/OverridesJavaxInjectableMethodTest.java index 0962f498cd2..991432417b0 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/OverridesJavaxInjectableMethodTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/OverridesJavaxInjectableMethodTest.java @@ -73,7 +73,8 @@ public class TestClass3 extends TestClass2 { // BUG: Diagnostic contains: @Inject public void foo() {} } -}""") +}\ +""") .doTest(); } @@ -140,7 +141,8 @@ public class TestClass9 extends TestClass3 { @SuppressWarnings("OverridesJavaxInjectableMethod") public void foo() {} } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/ProvidesMethodOutsideOfModuleTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/ProvidesMethodOutsideOfModuleTest.java index e87d5e7fdfb..da73b4493aa 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/ProvidesMethodOutsideOfModuleTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inject/guice/ProvidesMethodOutsideOfModuleTest.java @@ -81,7 +81,8 @@ int thisIsNotOk() { return 42; } } - }""") + }\ + """) .doTest(); } @@ -148,7 +149,8 @@ int providesFoo() { return 42; } } - }""") + }\ + """) .doTest(); } } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/nullness/EqualsBrokenForNullTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/nullness/EqualsBrokenForNullTest.java index b60082bf736..000907558b1 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/nullness/EqualsBrokenForNullTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/nullness/EqualsBrokenForNullTest.java @@ -216,7 +216,8 @@ public boolean equals(Object o) { return that.a == a; } } - }""") + }\ + """) .doTest(); } @@ -352,7 +353,8 @@ public boolean equals(Object o) { return that.a == a; } } -}""") +}\ +""") .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/nullness/NullablePrimitiveTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/nullness/NullablePrimitiveTest.java index 55bd25cc18b..3af10f241aa 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/nullness/NullablePrimitiveTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/nullness/NullablePrimitiveTest.java @@ -59,7 +59,8 @@ public void method( public int method() { return 0; } - }""") + }\ + """) .doTest(); } @@ -85,7 +86,8 @@ public void method(@Nullable Integer a) {} public Integer method() { return Integer.valueOf(0); } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/nullness/UnnecessaryCheckNotNullTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/nullness/UnnecessaryCheckNotNullTest.java index d66509f2596..32c3e603c52 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/nullness/UnnecessaryCheckNotNullTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/nullness/UnnecessaryCheckNotNullTest.java @@ -239,7 +239,8 @@ public void error_fully_qualified_import_requireNonNull() { // BUG: Diagnostic contains: remove this line java.util.Objects.requireNonNull("string literal"); } - }""") + }\ + """) .doTest(); } @@ -288,7 +289,8 @@ public void go() { com.google.common.base.Verify.verifyNotNull(testObj, "this is ok"); java.util.Objects.requireNonNull(testObj, "this is ok"); } - }""") + }\ + """) .doTest(); } @@ -429,7 +431,8 @@ public Tester getTester() { return tester; } } - }""") + }\ + """) .doTest(); } @@ -455,7 +458,8 @@ public void test() { Preconditions.checkNotNull(obj1, "%s should not be null", "obj1"); Preconditions.checkNotNull(obj1.toString()); } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/nullness/UnsafeWildcardTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/nullness/UnsafeWildcardTest.java index 9dcf2cc4099..01d21b42ac7 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/nullness/UnsafeWildcardTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/nullness/UnsafeWildcardTest.java @@ -76,7 +76,8 @@ public static void main(String... args) { // BUG: Diagnostic contains: impossible new Impl<>(Stream.of(null, null)).apply("boom"); } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/overloading/InconsistentOverloadsTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/overloading/InconsistentOverloadsTest.java index 35389f6d257..6ddcfe5c91b 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/overloading/InconsistentOverloadsTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/overloading/InconsistentOverloadsTest.java @@ -66,7 +66,8 @@ public void quux(int x, int y, String string) {} public void norf(int x, int y) {} public void norf(Object object, String string) {} - }""") + }\ + """) .doTest(); } @@ -110,7 +111,8 @@ int quux(@Bar @Baz Object object) { // BUG: Diagnostic contains: norf(String string, Object object) abstract int norf(Object object, @Baz @Bar String string); - }""") + }\ + """) .doTest(); } @@ -151,7 +153,8 @@ public void quux(int x, int y, String string) {} // BUG: Diagnostic contains: quux(int x, int y, Object object) public void quux(Object object, int y, int x) {} - }""") + }\ + """) .doTest(); } @@ -179,7 +182,8 @@ public void bar(int x) {} // BUG: Diagnostic contains: bar(int x, List> strings) public void bar(List> strings, int x) {} -}""") +}\ +""") .doTest(); } @@ -213,7 +217,8 @@ public void foo(int z, int x, int y) {} public void bar(int x, int y, String string, Object object) {} public void baz(int x) {} - }""") + }\ + """) .doTest(); } @@ -234,7 +239,8 @@ public void foo(int x, int y, Object object) {} // BUG: Diagnostic contains: foo(Object object, int x, int y, String string) public void foo(String string, int y, Object object, int x) {} - }""") + }\ + """) .doTest(); } @@ -264,7 +270,8 @@ public void foo(int y, int x, String... rest) {} abstract void bar(float y, String string, float x, float z); abstract void bar(Object... rest); - }""") + }\ + """) .doTest(); } @@ -301,7 +308,8 @@ void someMethod(int bar, String foo, List baz) {} // String> fizz) void someMethod(int bar, String foo, List baz, Map fizz) {} } -}""") +}\ +""") .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/time/TimeUnitMismatchTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/time/TimeUnitMismatchTest.java index 09588927822..600a30eb57d 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/time/TimeUnitMismatchTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/time/TimeUnitMismatchTest.java @@ -133,7 +133,8 @@ void optionalGet() { // BUG: Diagnostic contains: expected milliseconds but was nanoseconds long millis = maybeNanos.get(); } - }""") + }\ + """) .doTest(); } @@ -218,7 +219,8 @@ void optionalGet() { Optional maybeNanos = Optional.of(0L); long nanos = maybeNanos.get(); } - }""") + }\ + """) .doTest(); } diff --git a/core/src/test/java/com/google/errorprone/dataflow/nullnesspropagation/NullnessPropagationTest.java b/core/src/test/java/com/google/errorprone/dataflow/nullnesspropagation/NullnessPropagationTest.java index 216792412ef..6f939270560 100644 --- a/core/src/test/java/com/google/errorprone/dataflow/nullnesspropagation/NullnessPropagationTest.java +++ b/core/src/test/java/com/google/errorprone/dataflow/nullnesspropagation/NullnessPropagationTest.java @@ -290,7 +290,8 @@ public void stringConcatenation(String a, String b) { // BUG: Diagnostic contains: (Non-null) triggerNullnessChecker(null + (String) null); } -}""") +}\ +""") .doTest(); } @@ -628,7 +629,8 @@ public void optionalMethodsReturnNonNullUnlessAnnotated() { // BUG: Diagnostic contains: (Nullable) triggerNullnessChecker(myOptional.orNull()); } -}""") +}\ +""") .doTest(); } @@ -894,7 +896,8 @@ public void loop2() { comingValue = new Object(); } } -}""") +}\ +""") .doTest(); } @@ -1160,7 +1163,8 @@ public void equalOneNullableOtherNonNull(String nullableParam) { } // TODO(eaftan): tests for bottom? -}""") +}\ +""") .doTest(); } @@ -1426,7 +1430,8 @@ public void notEqualOneNullableOtherNonNull(String nullableParam) { } // TODO(eaftan): tests for bottom? -}""") +}\ +""") .doTest(); } @@ -1615,7 +1620,8 @@ void method() { static class HasStaticFields { static String staticStringField; } -}""") +}\ +""") .doTest(); } @@ -1783,7 +1789,8 @@ public void nullableAssignmentToPrimitiveFieldExpressionValue() { // BUG: Diagnostic contains: (Non-null) triggerNullnessCheckerOnPrimitive(mc.field = boxedIntReturningMethod()); } -}""") +}\ +""") .doTest(); } @@ -1830,7 +1837,8 @@ void tryWithResources() throws Exception { T something() { return null; } -}""") +}\ +""") .doTest(); }