void sink(BiFunction, P> fun) {}",
- "}")
+ """
+ import java.util.function.BiFunction;
+ import java.util.function.Function;
+ import reactor.core.publisher.Flux;
+ import reactor.core.publisher.Mono;
+
+ class A {
+ void m() {
+ // BUG: Diagnostic contains:
+ Flux.just(1).flatMap(Flux::just);
+ // BUG: Diagnostic contains:
+ Flux.just(1).flatMap(i -> Flux.just(String.valueOf(i)));
+ // BUG: Diagnostic contains:
+ Flux.just(1).flatMapSequential(Flux::just);
+ // BUG: Diagnostic contains:
+ Flux.just(1).flatMapSequential(i -> Flux.just(String.valueOf(i)));
+ // BUG: Diagnostic contains:
+ Flux.just(1, 2).groupBy(i -> i).flatMap(Flux::just);
+ // BUG: Diagnostic contains:
+ Flux.just(1, 2).groupBy(i -> i).flatMap(i -> Flux.just(String.valueOf(i)));
+ // BUG: Diagnostic contains:
+ Flux.just(1, 2).groupBy(i -> i).flatMapSequential(Flux::just);
+ // BUG: Diagnostic contains:
+ Flux.just(1, 2).groupBy(i -> i).flatMapSequential(i -> Flux.just(String.valueOf(i)));
+
+ Mono.just(1).flatMap(Mono::just);
+ Flux.just(1).concatMap(Flux::just);
+
+ Flux.just(1).flatMap(Flux::just, 1);
+ Flux.just(1).flatMap(Flux::just, 1, 1);
+ Flux.just(1).flatMap(Flux::just, throwable -> Flux.empty(), Flux::empty);
+
+ Flux.just(1).flatMapSequential(Flux::just, 1);
+ Flux.just(1).flatMapSequential(Flux::just, 1, 1);
+
+ // BUG: Diagnostic contains:
+ this.>sink(Flux::flatMap);
+ // BUG: Diagnostic contains:
+ this.>sink(Flux::flatMap);
+
+ // BUG: Diagnostic contains:
+ this.>sink(Flux::flatMapSequential);
+ // BUG: Diagnostic contains:
+ this.>sink(Flux::flatMapSequential);
+
+ this.>sink(Mono::flatMap);
+ }
+
+ private void sink(BiFunction, P> fun) {}
+ }
+ """)
.doTest();
}
@@ -69,32 +71,36 @@ void replacementFirstSuggestedFix() {
BugCheckerRefactoringTestHelper.newInstance(FluxFlatMapUsage.class, getClass())
.addInputLines(
"A.java",
- "import reactor.core.publisher.Flux;",
- "",
- "class A {",
- " private static final int MAX_CONCURRENCY = 8;",
- "",
- " void m() {",
- " Flux.just(1).flatMap(Flux::just);",
- " Flux.just(1).flatMapSequential(Flux::just);",
- " Flux.just(1, 2).groupBy(i -> i).flatMap(Flux::just);",
- " Flux.just(1, 2).groupBy(i -> i).flatMapSequential(Flux::just);",
- " }",
- "}")
+ """
+ import reactor.core.publisher.Flux;
+
+ class A {
+ private static final int MAX_CONCURRENCY = 8;
+
+ void m() {
+ Flux.just(1).flatMap(Flux::just);
+ Flux.just(1).flatMapSequential(Flux::just);
+ Flux.just(1, 2).groupBy(i -> i).flatMap(Flux::just);
+ Flux.just(1, 2).groupBy(i -> i).flatMapSequential(Flux::just);
+ }
+ }
+ """)
.addOutputLines(
"A.java",
- "import reactor.core.publisher.Flux;",
- "",
- "class A {",
- " private static final int MAX_CONCURRENCY = 8;",
- "",
- " void m() {",
- " Flux.just(1).concatMap(Flux::just);",
- " Flux.just(1).concatMap(Flux::just);",
- " Flux.just(1, 2).groupBy(i -> i).flatMap(Flux::just, MAX_CONCURRENCY);",
- " Flux.just(1, 2).groupBy(i -> i).flatMapSequential(Flux::just, MAX_CONCURRENCY);",
- " }",
- "}")
+ """
+ import reactor.core.publisher.Flux;
+
+ class A {
+ private static final int MAX_CONCURRENCY = 8;
+
+ void m() {
+ Flux.just(1).concatMap(Flux::just);
+ Flux.just(1).concatMap(Flux::just);
+ Flux.just(1, 2).groupBy(i -> i).flatMap(Flux::just, MAX_CONCURRENCY);
+ Flux.just(1, 2).groupBy(i -> i).flatMapSequential(Flux::just, MAX_CONCURRENCY);
+ }
+ }
+ """)
.doTest(TestMode.TEXT_MATCH);
}
@@ -104,32 +110,36 @@ void replacementSecondSuggestedFix() {
.setFixChooser(FixChoosers.SECOND)
.addInputLines(
"A.java",
- "import reactor.core.publisher.Flux;",
- "",
- "class A {",
- " private static final int MAX_CONCURRENCY = 8;",
- "",
- " void m() {",
- " Flux.just(1).flatMap(Flux::just);",
- " Flux.just(1).flatMapSequential(Flux::just);",
- " Flux.just(1, 2).groupBy(i -> i).flatMap(Flux::just);",
- " Flux.just(1, 2).groupBy(i -> i).flatMapSequential(Flux::just);",
- " }",
- "}")
+ """
+ import reactor.core.publisher.Flux;
+
+ class A {
+ private static final int MAX_CONCURRENCY = 8;
+
+ void m() {
+ Flux.just(1).flatMap(Flux::just);
+ Flux.just(1).flatMapSequential(Flux::just);
+ Flux.just(1, 2).groupBy(i -> i).flatMap(Flux::just);
+ Flux.just(1, 2).groupBy(i -> i).flatMapSequential(Flux::just);
+ }
+ }
+ """)
.addOutputLines(
"A.java",
- "import reactor.core.publisher.Flux;",
- "",
- "class A {",
- " private static final int MAX_CONCURRENCY = 8;",
- "",
- " void m() {",
- " Flux.just(1).flatMap(Flux::just, MAX_CONCURRENCY);",
- " Flux.just(1).flatMapSequential(Flux::just, MAX_CONCURRENCY);",
- " Flux.just(1, 2).groupBy(i -> i).concatMap(Flux::just);",
- " Flux.just(1, 2).groupBy(i -> i).concatMap(Flux::just);",
- " }",
- "}")
+ """
+ import reactor.core.publisher.Flux;
+
+ class A {
+ private static final int MAX_CONCURRENCY = 8;
+
+ void m() {
+ Flux.just(1).flatMap(Flux::just, MAX_CONCURRENCY);
+ Flux.just(1).flatMapSequential(Flux::just, MAX_CONCURRENCY);
+ Flux.just(1, 2).groupBy(i -> i).concatMap(Flux::just);
+ Flux.just(1, 2).groupBy(i -> i).concatMap(Flux::just);
+ }
+ }
+ """)
.doTest(TestMode.TEXT_MATCH);
}
}
diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxImplicitBlockTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxImplicitBlockTest.java
index 91cecd3439..3dc7db5bca 100644
--- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxImplicitBlockTest.java
+++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxImplicitBlockTest.java
@@ -21,36 +21,38 @@ void identification() {
m -> Stream.of("SuppressWarnings", "toImmutableList", "toList").allMatch(m::contains))
.addSourceLines(
"A.java",
- "import com.google.common.collect.ImmutableList;",
- "import java.util.stream.Stream;",
- "import reactor.core.publisher.Flux;",
- "",
- "class A {",
- " void m() {",
- " // BUG: Diagnostic matches: X",
- " Flux.just(1).toIterable();",
- " // BUG: Diagnostic matches: X",
- " Flux.just(2).toStream();",
- " // BUG: Diagnostic matches: X",
- " long count = Flux.just(3).toStream().count();",
- "",
- " Flux.just(4).toIterable(1);",
- " Flux.just(5).toIterable(2, null);",
- " Flux.just(6).toStream(3);",
- " new Foo().toIterable();",
- " new Foo().toStream();",
- " }",
- "",
- " class Foo {",
- " Iterable toIterable() {",
- " return ImmutableList.of();",
- " }",
- "",
- " Stream toStream() {",
- " return Stream.empty();",
- " }",
- " }",
- "}")
+ """
+ import com.google.common.collect.ImmutableList;
+ import java.util.stream.Stream;
+ import reactor.core.publisher.Flux;
+
+ class A {
+ void m() {
+ // BUG: Diagnostic matches: X
+ Flux.just(1).toIterable();
+ // BUG: Diagnostic matches: X
+ Flux.just(2).toStream();
+ // BUG: Diagnostic matches: X
+ long count = Flux.just(3).toStream().count();
+
+ Flux.just(4).toIterable(1);
+ Flux.just(5).toIterable(2, null);
+ Flux.just(6).toStream(3);
+ new Foo().toIterable();
+ new Foo().toStream();
+ }
+
+ class Foo {
+ Iterable toIterable() {
+ return ImmutableList.of();
+ }
+
+ Stream toStream() {
+ return Stream.empty();
+ }
+ }
+ }
+ """)
.doTest();
}
@@ -61,16 +63,18 @@ void identificationWithoutGuavaOnClasspath() {
.expectErrorMessage("X", m -> !m.contains("toImmutableList"))
.addSourceLines(
"A.java",
- "import reactor.core.publisher.Flux;",
- "",
- "class A {",
- " void m() {",
- " // BUG: Diagnostic matches: X",
- " Flux.just(1).toIterable();",
- " // BUG: Diagnostic matches: X",
- " Flux.just(2).toStream();",
- " }",
- "}")
+ """
+ import reactor.core.publisher.Flux;
+
+ class A {
+ void m() {
+ // BUG: Diagnostic matches: X
+ Flux.just(1).toIterable();
+ // BUG: Diagnostic matches: X
+ Flux.just(2).toStream();
+ }
+ }
+ """)
.doTest();
}
@@ -79,25 +83,29 @@ void replacementFirstSuggestedFix() {
BugCheckerRefactoringTestHelper.newInstance(FluxImplicitBlock.class, getClass())
.addInputLines(
"A.java",
- "import reactor.core.publisher.Flux;",
- "",
- "class A {",
- " void m() {",
- " Flux.just(1).toIterable();",
- " Flux.just(2).toStream();",
- " }",
- "}")
+ """
+ import reactor.core.publisher.Flux;
+
+ class A {
+ void m() {
+ Flux.just(1).toIterable();
+ Flux.just(2).toStream();
+ }
+ }
+ """)
.addOutputLines(
"A.java",
- "import reactor.core.publisher.Flux;",
- "",
- "class A {",
- " @SuppressWarnings(\"FluxImplicitBlock\")",
- " void m() {",
- " Flux.just(1).toIterable();",
- " Flux.just(2).toStream();",
- " }",
- "}")
+ """
+ import reactor.core.publisher.Flux;
+
+ class A {
+ @SuppressWarnings("FluxImplicitBlock")
+ void m() {
+ Flux.just(1).toIterable();
+ Flux.just(2).toStream();
+ }
+ }
+ """)
.doTest(TestMode.TEXT_MATCH);
}
@@ -107,34 +115,38 @@ void replacementSecondSuggestedFix() {
.setFixChooser(SECOND)
.addInputLines(
"A.java",
- "import reactor.core.publisher.Flux;",
- "",
- "class A {",
- " void m() {",
- " Flux.just(1).toIterable();",
- " Flux.just(2).toStream();",
- " Flux.just(3).toIterable().iterator();",
- " Flux.just(4).toStream().count();",
- " Flux.just(5) /* a */./* b */ toIterable /* c */(/* d */ ) /* e */;",
- " Flux.just(6) /* a */./* b */ toStream /* c */(/* d */ ) /* e */;",
- " }",
- "}")
+ """
+ import reactor.core.publisher.Flux;
+
+ class A {
+ void m() {
+ Flux.just(1).toIterable();
+ Flux.just(2).toStream();
+ Flux.just(3).toIterable().iterator();
+ Flux.just(4).toStream().count();
+ Flux.just(5) /* a */./* b */ toIterable /* c */(/* d */ ) /* e */;
+ Flux.just(6) /* a */./* b */ toStream /* c */(/* d */ ) /* e */;
+ }
+ }
+ """)
.addOutputLines(
"A.java",
- "import static com.google.common.collect.ImmutableList.toImmutableList;",
- "",
- "import reactor.core.publisher.Flux;",
- "",
- "class A {",
- " void m() {",
- " Flux.just(1).collect(toImmutableList()).block();",
- " Flux.just(2).collect(toImmutableList()).block().stream();",
- " Flux.just(3).collect(toImmutableList()).block().iterator();",
- " Flux.just(4).collect(toImmutableList()).block().stream().count();",
- " Flux.just(5).collect(toImmutableList()).block() /* e */;",
- " Flux.just(6).collect(toImmutableList()).block().stream() /* e */;",
- " }",
- "}")
+ """
+ import static com.google.common.collect.ImmutableList.toImmutableList;
+
+ import reactor.core.publisher.Flux;
+
+ class A {
+ void m() {
+ Flux.just(1).collect(toImmutableList()).block();
+ Flux.just(2).collect(toImmutableList()).block().stream();
+ Flux.just(3).collect(toImmutableList()).block().iterator();
+ Flux.just(4).collect(toImmutableList()).block().stream().count();
+ Flux.just(5).collect(toImmutableList()).block() /* e */;
+ Flux.just(6).collect(toImmutableList()).block().stream() /* e */;
+ }
+ }
+ """)
.doTest(TestMode.TEXT_MATCH);
}
@@ -144,34 +156,38 @@ void replacementThirdSuggestedFix() {
.setFixChooser(THIRD)
.addInputLines(
"A.java",
- "import reactor.core.publisher.Flux;",
- "",
- "class A {",
- " void m() {",
- " Flux.just(1).toIterable();",
- " Flux.just(2).toStream();",
- " Flux.just(3).toIterable().iterator();",
- " Flux.just(4).toStream().count();",
- " Flux.just(5) /* a */./* b */ toIterable /* c */(/* d */ ) /* e */;",
- " Flux.just(6) /* a */./* b */ toStream /* c */(/* d */ ) /* e */;",
- " }",
- "}")
+ """
+ import reactor.core.publisher.Flux;
+
+ class A {
+ void m() {
+ Flux.just(1).toIterable();
+ Flux.just(2).toStream();
+ Flux.just(3).toIterable().iterator();
+ Flux.just(4).toStream().count();
+ Flux.just(5) /* a */./* b */ toIterable /* c */(/* d */ ) /* e */;
+ Flux.just(6) /* a */./* b */ toStream /* c */(/* d */ ) /* e */;
+ }
+ }
+ """)
.addOutputLines(
"A.java",
- "import static java.util.stream.Collectors.toList;",
- "",
- "import reactor.core.publisher.Flux;",
- "",
- "class A {",
- " void m() {",
- " Flux.just(1).collect(toList()).block();",
- " Flux.just(2).collect(toList()).block().stream();",
- " Flux.just(3).collect(toList()).block().iterator();",
- " Flux.just(4).collect(toList()).block().stream().count();",
- " Flux.just(5).collect(toList()).block() /* e */;",
- " Flux.just(6).collect(toList()).block().stream() /* e */;",
- " }",
- "}")
+ """
+ import static java.util.stream.Collectors.toList;
+
+ import reactor.core.publisher.Flux;
+
+ class A {
+ void m() {
+ Flux.just(1).collect(toList()).block();
+ Flux.just(2).collect(toList()).block().stream();
+ Flux.just(3).collect(toList()).block().iterator();
+ Flux.just(4).collect(toList()).block().stream().count();
+ Flux.just(5).collect(toList()).block() /* e */;
+ Flux.just(6).collect(toList()).block().stream() /* e */;
+ }
+ }
+ """)
.doTest(TestMode.TEXT_MATCH);
}
}
diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenationTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenationTest.java
index cf300ebf4d..737fab3d3d 100644
--- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenationTest.java
+++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenationTest.java
@@ -11,294 +11,296 @@ void identification() {
CompilationTestHelper.newInstance(FormatStringConcatenation.class, getClass())
.addSourceLines(
"A.java",
- "import static com.google.common.base.Preconditions.checkArgument;",
- "import static com.google.common.base.Preconditions.checkNotNull;",
- "import static com.google.common.base.Preconditions.checkState;",
- "import static com.google.common.base.Verify.verify;",
- "import static org.assertj.core.api.Assertions.assertThat;",
- "import static org.assertj.core.api.SoftAssertions.assertSoftly;",
- "",
- "import java.util.Formatter;",
- "import java.util.Locale;",
- "import org.assertj.core.api.Assertions;",
- "import org.assertj.core.api.BDDAssertions;",
- "import org.assertj.core.api.Fail;",
- "import org.assertj.core.api.ThrowableAssertAlternative;",
- "import org.assertj.core.api.WithAssertions;",
- "import org.slf4j.Logger;",
- "import org.slf4j.LoggerFactory;",
- "import org.slf4j.Marker;",
- "",
- "class A {",
- " private static final Logger LOG = LoggerFactory.getLogger(A.class);",
- "",
- " void negative() {",
- " hashCode();",
- " equals(new A());",
- " equals(toString());",
- " equals(0);",
- " equals(\"str\");",
- " equals(\"str\" + 0);",
- " equals(0 + 0);",
- " equals(0 - 0);",
- " equals(\"str \" + toString());",
- " }",
- "",
- " void assertj() {",
- " assertThat(0).overridingErrorMessage(toString());",
- " assertThat(0).overridingErrorMessage(\"str\");",
- " assertThat(0).overridingErrorMessage(\"str \" + 0);",
- " assertThat(0).overridingErrorMessage(\"str %s\", 2 * 3);",
- " assertThat(0).overridingErrorMessage(\"str %s\", toString());",
- " // BUG: Diagnostic contains:",
- " assertThat(0).overridingErrorMessage(\"str \" + hashCode() / 2);",
- " // BUG: Diagnostic contains:",
- " assertThat(0).overridingErrorMessage((\"str \" + toString()));",
- " // BUG: Diagnostic contains:",
- " assertThat(0).overridingErrorMessage(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " assertThat(0).overridingErrorMessage(\"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " assertThat(0).withFailMessage(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " assertThat(0).withFailMessage(\"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " assertSoftly(softly -> softly.fail(\"str \" + toString()));",
- " // BUG: Diagnostic contains:",
- " assertSoftly(softly -> softly.fail(\"%s \" + toString(), \"arg\"));",
- " assertSoftly(softly -> softly.fail(\"str \" + toString(), new Throwable()));",
- "",
- " // BUG: Diagnostic contains:",
- " assertThat(\"\").isEqualTo(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " assertThat(\"\").isEqualTo(\"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " assertThat(new Error()).hasMessage(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " assertThat(new Error()).hasMessage(\"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " assertThat(new Error()).hasMessageContaining(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " assertThat(new Error()).hasMessageContaining(\"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " assertThat(new Error()).hasMessageEndingWith(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " assertThat(new Error()).hasMessageEndingWith(\"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " assertThat(new Error()).hasMessageStartingWith(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " assertThat(new Error()).hasMessageStartingWith(\"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " assertThat(new Error()).hasRootCauseMessage(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " assertThat(new Error()).hasRootCauseMessage(\"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " assertThat(new Error()).hasStackTraceContaining(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " assertThat(new Error()).hasStackTraceContaining(\"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " assertThat(0).as(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " assertThat(0).as(\"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " assertThat(0).describedAs(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " assertThat(0).describedAs(\"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " ((ThrowableAssertAlternative) null).withMessage(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " ((ThrowableAssertAlternative) null).withMessage(\"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " ((ThrowableAssertAlternative) null).withMessageContaining(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " ((ThrowableAssertAlternative) null).withMessageContaining(\"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " ((ThrowableAssertAlternative) null).withMessageEndingWith(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " ((ThrowableAssertAlternative) null).withMessageEndingWith(\"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " ((ThrowableAssertAlternative) null).withMessageStartingWith(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " ((ThrowableAssertAlternative) null).withMessageStartingWith(\"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " ((ThrowableAssertAlternative) null).withStackTraceContaining(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " ((ThrowableAssertAlternative) null).withStackTraceContaining(\"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " ((WithAssertions) null).fail(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " ((WithAssertions) null).fail(\"%s \" + toString(), \"arg\");",
- " ((WithAssertions) null).fail(\"str \" + toString(), new Throwable());",
- "",
- " // BUG: Diagnostic contains:",
- " Assertions.fail(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " Assertions.fail(\"%s \" + toString(), \"arg\");",
- " Assertions.fail(\"str \" + toString(), new Throwable());",
- "",
- " // BUG: Diagnostic contains:",
- " BDDAssertions.fail(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " BDDAssertions.fail(\"%s \" + toString(), \"arg\");",
- " BDDAssertions.fail(\"str \" + toString(), new Throwable());",
- "",
- " // BUG: Diagnostic contains:",
- " Fail.fail(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " Fail.fail(\"%s \" + toString(), \"arg\");",
- " Fail.fail(\"str \" + toString(), new Throwable());",
- " }",
- "",
- " void guava() {",
- " checkArgument(true);",
- " checkArgument(true, toString());",
- " checkArgument(true, \"str\");",
- " checkArgument(true, \"str \" + 0);",
- " checkArgument(true, \"str %s\", 2 * 3);",
- " checkArgument(true, \"str %s\", toString());",
- " // BUG: Diagnostic contains:",
- " checkArgument(true, \"str \" + hashCode() / 2);",
- " // BUG: Diagnostic contains:",
- " checkArgument(true, (\"str \" + toString()));",
- " // BUG: Diagnostic contains:",
- " checkArgument(true, \"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " checkArgument(true, \"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " checkNotNull(true, \"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " checkNotNull(true, \"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " checkState(true, \"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " checkState(true, \"%s \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " verify(true, \"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " verify(true, \"%s \" + toString(), \"arg\");",
- " }",
- "",
- " void jdk() {",
- " String.format(\"str\");",
- " String.format(\"str \" + 0);",
- " String.format(\"str {}\", 2 * 3);",
- " String.format(\"str {}\", toString());",
- " // BUG: Diagnostic contains:",
- " String.format(\"str \" + hashCode() / 2);",
- " // BUG: Diagnostic contains:",
- " String.format((\"str \" + toString()));",
- " // BUG: Diagnostic contains:",
- " String.format(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " String.format(\"{} \" + toString(), \"arg\");",
- "",
- " String.format(Locale.ROOT, \"str\");",
- " String.format(Locale.ROOT, \"str \" + 0);",
- " String.format(Locale.ROOT, \"str {}\", 2 * 3);",
- " String.format(Locale.ROOT, \"str {}\", toString());",
- " // BUG: Diagnostic contains:",
- " String.format(Locale.ROOT, (\"str \" + toString()));",
- " // BUG: Diagnostic contains:",
- " String.format(Locale.ROOT, \"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " String.format(Locale.ROOT, \"{} \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " new Formatter().format(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " new Formatter().format(\"{} \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " new Formatter().format(Locale.ROOT, \"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " new Formatter().format(Locale.ROOT, \"{} \" + toString(), \"arg\");",
- " }",
- "",
- " void slf4j() {",
- " LOG.debug(\"str\");",
- " LOG.debug(\"str \" + 0);",
- " LOG.debug(\"str {}\", 2 * 3);",
- " LOG.debug(\"str {}\", toString());",
- " // BUG: Diagnostic contains:",
- " LOG.debug(\"str \" + hashCode() / 2);",
- " // BUG: Diagnostic contains:",
- " LOG.debug((\"str \" + toString()));",
- " // BUG: Diagnostic contains:",
- " LOG.debug(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " LOG.debug(\"{} \" + toString(), \"arg\");",
- "",
- " LOG.debug((Marker) null, \"str\");",
- " LOG.debug((Marker) null, \"str \" + 0);",
- " LOG.debug((Marker) null, \"str {}\", 2 * 3);",
- " LOG.debug((Marker) null, \"str {}\", toString());",
- " // BUG: Diagnostic contains:",
- " LOG.debug((Marker) null, (\"str \" + toString()));",
- " // BUG: Diagnostic contains:",
- " LOG.debug((Marker) null, \"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " LOG.debug((Marker) null, \"{} \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " LOG.error(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " LOG.error(\"{} \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " LOG.error((Marker) null, \"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " LOG.error((Marker) null, \"{} \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " LOG.info(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " LOG.info(\"{} \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " LOG.info((Marker) null, \"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " LOG.info((Marker) null, \"{} \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " LOG.trace(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " LOG.trace(\"{} \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " LOG.trace((Marker) null, \"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " LOG.trace((Marker) null, \"{} \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " LOG.warn(\"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " LOG.warn(\"{} \" + toString(), \"arg\");",
- "",
- " // BUG: Diagnostic contains:",
- " LOG.warn((Marker) null, \"str \" + toString());",
- " // BUG: Diagnostic contains:",
- " LOG.warn((Marker) null, \"{} \" + toString(), \"arg\");",
- " }",
- "}")
+ """
+ import static com.google.common.base.Preconditions.checkArgument;
+ import static com.google.common.base.Preconditions.checkNotNull;
+ import static com.google.common.base.Preconditions.checkState;
+ import static com.google.common.base.Verify.verify;
+ import static org.assertj.core.api.Assertions.assertThat;
+ import static org.assertj.core.api.SoftAssertions.assertSoftly;
+
+ import java.util.Formatter;
+ import java.util.Locale;
+ import org.assertj.core.api.Assertions;
+ import org.assertj.core.api.BDDAssertions;
+ import org.assertj.core.api.Fail;
+ import org.assertj.core.api.ThrowableAssertAlternative;
+ import org.assertj.core.api.WithAssertions;
+ import org.slf4j.Logger;
+ import org.slf4j.LoggerFactory;
+ import org.slf4j.Marker;
+
+ class A {
+ private static final Logger LOG = LoggerFactory.getLogger(A.class);
+
+ void negative() {
+ hashCode();
+ equals(new A());
+ equals(toString());
+ equals(0);
+ equals("str");
+ equals("str" + 0);
+ equals(0 + 0);
+ equals(0 - 0);
+ equals("str " + toString());
+ }
+
+ void assertj() {
+ assertThat(0).overridingErrorMessage(toString());
+ assertThat(0).overridingErrorMessage("str");
+ assertThat(0).overridingErrorMessage("str " + 0);
+ assertThat(0).overridingErrorMessage("str %s", 2 * 3);
+ assertThat(0).overridingErrorMessage("str %s", toString());
+ // BUG: Diagnostic contains:
+ assertThat(0).overridingErrorMessage("str " + hashCode() / 2);
+ // BUG: Diagnostic contains:
+ assertThat(0).overridingErrorMessage(("str " + toString()));
+ // BUG: Diagnostic contains:
+ assertThat(0).overridingErrorMessage("str " + toString());
+ // BUG: Diagnostic contains:
+ assertThat(0).overridingErrorMessage("%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ assertThat(0).withFailMessage("str " + toString());
+ // BUG: Diagnostic contains:
+ assertThat(0).withFailMessage("%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ assertSoftly(softly -> softly.fail("str " + toString()));
+ // BUG: Diagnostic contains:
+ assertSoftly(softly -> softly.fail("%s " + toString(), "arg"));
+ assertSoftly(softly -> softly.fail("str " + toString(), new Throwable()));
+
+ // BUG: Diagnostic contains:
+ assertThat("").isEqualTo("str " + toString());
+ // BUG: Diagnostic contains:
+ assertThat("").isEqualTo("%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ assertThat(new Error()).hasMessage("str " + toString());
+ // BUG: Diagnostic contains:
+ assertThat(new Error()).hasMessage("%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ assertThat(new Error()).hasMessageContaining("str " + toString());
+ // BUG: Diagnostic contains:
+ assertThat(new Error()).hasMessageContaining("%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ assertThat(new Error()).hasMessageEndingWith("str " + toString());
+ // BUG: Diagnostic contains:
+ assertThat(new Error()).hasMessageEndingWith("%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ assertThat(new Error()).hasMessageStartingWith("str " + toString());
+ // BUG: Diagnostic contains:
+ assertThat(new Error()).hasMessageStartingWith("%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ assertThat(new Error()).hasRootCauseMessage("str " + toString());
+ // BUG: Diagnostic contains:
+ assertThat(new Error()).hasRootCauseMessage("%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ assertThat(new Error()).hasStackTraceContaining("str " + toString());
+ // BUG: Diagnostic contains:
+ assertThat(new Error()).hasStackTraceContaining("%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ assertThat(0).as("str " + toString());
+ // BUG: Diagnostic contains:
+ assertThat(0).as("%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ assertThat(0).describedAs("str " + toString());
+ // BUG: Diagnostic contains:
+ assertThat(0).describedAs("%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ ((ThrowableAssertAlternative) null).withMessage("str " + toString());
+ // BUG: Diagnostic contains:
+ ((ThrowableAssertAlternative) null).withMessage("%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ ((ThrowableAssertAlternative) null).withMessageContaining("str " + toString());
+ // BUG: Diagnostic contains:
+ ((ThrowableAssertAlternative) null).withMessageContaining("%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ ((ThrowableAssertAlternative) null).withMessageEndingWith("str " + toString());
+ // BUG: Diagnostic contains:
+ ((ThrowableAssertAlternative) null).withMessageEndingWith("%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ ((ThrowableAssertAlternative) null).withMessageStartingWith("str " + toString());
+ // BUG: Diagnostic contains:
+ ((ThrowableAssertAlternative) null).withMessageStartingWith("%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ ((ThrowableAssertAlternative) null).withStackTraceContaining("str " + toString());
+ // BUG: Diagnostic contains:
+ ((ThrowableAssertAlternative) null).withStackTraceContaining("%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ ((WithAssertions) null).fail("str " + toString());
+ // BUG: Diagnostic contains:
+ ((WithAssertions) null).fail("%s " + toString(), "arg");
+ ((WithAssertions) null).fail("str " + toString(), new Throwable());
+
+ // BUG: Diagnostic contains:
+ Assertions.fail("str " + toString());
+ // BUG: Diagnostic contains:
+ Assertions.fail("%s " + toString(), "arg");
+ Assertions.fail("str " + toString(), new Throwable());
+
+ // BUG: Diagnostic contains:
+ BDDAssertions.fail("str " + toString());
+ // BUG: Diagnostic contains:
+ BDDAssertions.fail("%s " + toString(), "arg");
+ BDDAssertions.fail("str " + toString(), new Throwable());
+
+ // BUG: Diagnostic contains:
+ Fail.fail("str " + toString());
+ // BUG: Diagnostic contains:
+ Fail.fail("%s " + toString(), "arg");
+ Fail.fail("str " + toString(), new Throwable());
+ }
+
+ void guava() {
+ checkArgument(true);
+ checkArgument(true, toString());
+ checkArgument(true, "str");
+ checkArgument(true, "str " + 0);
+ checkArgument(true, "str %s", 2 * 3);
+ checkArgument(true, "str %s", toString());
+ // BUG: Diagnostic contains:
+ checkArgument(true, "str " + hashCode() / 2);
+ // BUG: Diagnostic contains:
+ checkArgument(true, ("str " + toString()));
+ // BUG: Diagnostic contains:
+ checkArgument(true, "str " + toString());
+ // BUG: Diagnostic contains:
+ checkArgument(true, "%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ checkNotNull(true, "str " + toString());
+ // BUG: Diagnostic contains:
+ checkNotNull(true, "%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ checkState(true, "str " + toString());
+ // BUG: Diagnostic contains:
+ checkState(true, "%s " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ verify(true, "str " + toString());
+ // BUG: Diagnostic contains:
+ verify(true, "%s " + toString(), "arg");
+ }
+
+ void jdk() {
+ String.format("str");
+ String.format("str " + 0);
+ String.format("str {}", 2 * 3);
+ String.format("str {}", toString());
+ // BUG: Diagnostic contains:
+ String.format("str " + hashCode() / 2);
+ // BUG: Diagnostic contains:
+ String.format(("str " + toString()));
+ // BUG: Diagnostic contains:
+ String.format("str " + toString());
+ // BUG: Diagnostic contains:
+ String.format("{} " + toString(), "arg");
+
+ String.format(Locale.ROOT, "str");
+ String.format(Locale.ROOT, "str " + 0);
+ String.format(Locale.ROOT, "str {}", 2 * 3);
+ String.format(Locale.ROOT, "str {}", toString());
+ // BUG: Diagnostic contains:
+ String.format(Locale.ROOT, ("str " + toString()));
+ // BUG: Diagnostic contains:
+ String.format(Locale.ROOT, "str " + toString());
+ // BUG: Diagnostic contains:
+ String.format(Locale.ROOT, "{} " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ new Formatter().format("str " + toString());
+ // BUG: Diagnostic contains:
+ new Formatter().format("{} " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ new Formatter().format(Locale.ROOT, "str " + toString());
+ // BUG: Diagnostic contains:
+ new Formatter().format(Locale.ROOT, "{} " + toString(), "arg");
+ }
+
+ void slf4j() {
+ LOG.debug("str");
+ LOG.debug("str " + 0);
+ LOG.debug("str {}", 2 * 3);
+ LOG.debug("str {}", toString());
+ // BUG: Diagnostic contains:
+ LOG.debug("str " + hashCode() / 2);
+ // BUG: Diagnostic contains:
+ LOG.debug(("str " + toString()));
+ // BUG: Diagnostic contains:
+ LOG.debug("str " + toString());
+ // BUG: Diagnostic contains:
+ LOG.debug("{} " + toString(), "arg");
+
+ LOG.debug((Marker) null, "str");
+ LOG.debug((Marker) null, "str " + 0);
+ LOG.debug((Marker) null, "str {}", 2 * 3);
+ LOG.debug((Marker) null, "str {}", toString());
+ // BUG: Diagnostic contains:
+ LOG.debug((Marker) null, ("str " + toString()));
+ // BUG: Diagnostic contains:
+ LOG.debug((Marker) null, "str " + toString());
+ // BUG: Diagnostic contains:
+ LOG.debug((Marker) null, "{} " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ LOG.error("str " + toString());
+ // BUG: Diagnostic contains:
+ LOG.error("{} " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ LOG.error((Marker) null, "str " + toString());
+ // BUG: Diagnostic contains:
+ LOG.error((Marker) null, "{} " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ LOG.info("str " + toString());
+ // BUG: Diagnostic contains:
+ LOG.info("{} " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ LOG.info((Marker) null, "str " + toString());
+ // BUG: Diagnostic contains:
+ LOG.info((Marker) null, "{} " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ LOG.trace("str " + toString());
+ // BUG: Diagnostic contains:
+ LOG.trace("{} " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ LOG.trace((Marker) null, "str " + toString());
+ // BUG: Diagnostic contains:
+ LOG.trace((Marker) null, "{} " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ LOG.warn("str " + toString());
+ // BUG: Diagnostic contains:
+ LOG.warn("{} " + toString(), "arg");
+
+ // BUG: Diagnostic contains:
+ LOG.warn((Marker) null, "str " + toString());
+ // BUG: Diagnostic contains:
+ LOG.warn((Marker) null, "{} " + toString(), "arg");
+ }
+ }
+ """)
.doTest();
}
@@ -307,102 +309,106 @@ void replacement() {
BugCheckerRefactoringTestHelper.newInstance(FormatStringConcatenation.class, getClass())
.addInputLines(
"A.java",
- "import static com.google.common.base.Preconditions.checkArgument;",
- "import static org.assertj.core.api.Assertions.assertThat;",
- "",
- "import java.util.Locale;",
- "import org.slf4j.Logger;",
- "import org.slf4j.LoggerFactory;",
- "import org.slf4j.Marker;",
- "",
- "class A {",
- " private static final Logger LOG = LoggerFactory.getLogger(A.class);",
- "",
- " void assertj() {",
- " assertThat(0).overridingErrorMessage(toString() + \" str\");",
- " assertThat(0).overridingErrorMessage(\"str \" + toString());",
- " assertThat(0).overridingErrorMessage(toString() + toString());",
- " assertThat(0).overridingErrorMessage(\"str \" + toString() + \" word \" + new A().hashCode());",
- " assertThat(0).overridingErrorMessage(\"str \" + (toString() + \" word \") + (hashCode() / 2));",
- "",
- " // Flagged but not auto-fixed.",
- " assertThat(0).overridingErrorMessage(\"%s \" + toString(), \"arg\");",
- " }",
- "",
- " void guava() {",
- " checkArgument(true, \"str \" + toString());",
- "",
- " // Flagged but not auto-fixed.",
- " checkArgument(true, \"%s \" + toString(), \"arg\");",
- " }",
- "",
- " void jdk() {",
- " String.format(\"str \" + toString());",
- " String.format(Locale.ROOT, \"str \" + toString());",
- "",
- " // Flagged but not auto-fixed.",
- " String.format(\"{} \" + toString(), \"arg\");",
- " String.format(Locale.ROOT, \"{} \" + toString(), \"arg\");",
- " }",
- "",
- " void slf4j() {",
- " LOG.debug(\"str \" + toString());",
- " LOG.debug((Marker) null, \"str \" + toString());",
- "",
- " // Flagged but not auto-fixed.",
- " LOG.debug(\"{} \" + toString(), \"arg\");",
- " LOG.debug((Marker) null, \"{} \" + toString(), \"arg\");",
- " }",
- "}")
+ """
+ import static com.google.common.base.Preconditions.checkArgument;
+ import static org.assertj.core.api.Assertions.assertThat;
+
+ import java.util.Locale;
+ import org.slf4j.Logger;
+ import org.slf4j.LoggerFactory;
+ import org.slf4j.Marker;
+
+ class A {
+ private static final Logger LOG = LoggerFactory.getLogger(A.class);
+
+ void assertj() {
+ assertThat(0).overridingErrorMessage(toString() + " str");
+ assertThat(0).overridingErrorMessage("str " + toString());
+ assertThat(0).overridingErrorMessage(toString() + toString());
+ assertThat(0).overridingErrorMessage("str " + toString() + " word " + new A().hashCode());
+ assertThat(0).overridingErrorMessage("str " + (toString() + " word ") + (hashCode() / 2));
+
+ // Flagged but not auto-fixed.
+ assertThat(0).overridingErrorMessage("%s " + toString(), "arg");
+ }
+
+ void guava() {
+ checkArgument(true, "str " + toString());
+
+ // Flagged but not auto-fixed.
+ checkArgument(true, "%s " + toString(), "arg");
+ }
+
+ void jdk() {
+ String.format("str " + toString());
+ String.format(Locale.ROOT, "str " + toString());
+
+ // Flagged but not auto-fixed.
+ String.format("{} " + toString(), "arg");
+ String.format(Locale.ROOT, "{} " + toString(), "arg");
+ }
+
+ void slf4j() {
+ LOG.debug("str " + toString());
+ LOG.debug((Marker) null, "str " + toString());
+
+ // Flagged but not auto-fixed.
+ LOG.debug("{} " + toString(), "arg");
+ LOG.debug((Marker) null, "{} " + toString(), "arg");
+ }
+ }
+ """)
.addOutputLines(
"A.java",
- "import static com.google.common.base.Preconditions.checkArgument;",
- "import static org.assertj.core.api.Assertions.assertThat;",
- "",
- "import java.util.Locale;",
- "import org.slf4j.Logger;",
- "import org.slf4j.LoggerFactory;",
- "import org.slf4j.Marker;",
- "",
- "class A {",
- " private static final Logger LOG = LoggerFactory.getLogger(A.class);",
- "",
- " void assertj() {",
- " assertThat(0).overridingErrorMessage(\"%s str\", toString());",
- " assertThat(0).overridingErrorMessage(\"str %s\", toString());",
- " assertThat(0).overridingErrorMessage(\"%s%s\", toString(), toString());",
- " assertThat(0).overridingErrorMessage(\"str %s word %s\", toString(), new A().hashCode());",
- " assertThat(0).overridingErrorMessage(\"str %s word %s\", toString(), hashCode() / 2);",
- "",
- " // Flagged but not auto-fixed.",
- " assertThat(0).overridingErrorMessage(\"%s \" + toString(), \"arg\");",
- " }",
- "",
- " void guava() {",
- " checkArgument(true, \"str %s\", toString());",
- "",
- " // Flagged but not auto-fixed.",
- " checkArgument(true, \"%s \" + toString(), \"arg\");",
- " }",
- "",
- " void jdk() {",
- " String.format(\"str %s\", toString());",
- " String.format(Locale.ROOT, \"str %s\", toString());",
- "",
- " // Flagged but not auto-fixed.",
- " String.format(\"{} \" + toString(), \"arg\");",
- " String.format(Locale.ROOT, \"{} \" + toString(), \"arg\");",
- " }",
- "",
- " void slf4j() {",
- " LOG.debug(\"str {}\", toString());",
- " LOG.debug((Marker) null, \"str {}\", toString());",
- "",
- " // Flagged but not auto-fixed.",
- " LOG.debug(\"{} \" + toString(), \"arg\");",
- " LOG.debug((Marker) null, \"{} \" + toString(), \"arg\");",
- " }",
- "}")
+ """
+ import static com.google.common.base.Preconditions.checkArgument;
+ import static org.assertj.core.api.Assertions.assertThat;
+
+ import java.util.Locale;
+ import org.slf4j.Logger;
+ import org.slf4j.LoggerFactory;
+ import org.slf4j.Marker;
+
+ class A {
+ private static final Logger LOG = LoggerFactory.getLogger(A.class);
+
+ void assertj() {
+ assertThat(0).overridingErrorMessage("%s str", toString());
+ assertThat(0).overridingErrorMessage("str %s", toString());
+ assertThat(0).overridingErrorMessage("%s%s", toString(), toString());
+ assertThat(0).overridingErrorMessage("str %s word %s", toString(), new A().hashCode());
+ assertThat(0).overridingErrorMessage("str %s word %s", toString(), hashCode() / 2);
+
+ // Flagged but not auto-fixed.
+ assertThat(0).overridingErrorMessage("%s " + toString(), "arg");
+ }
+
+ void guava() {
+ checkArgument(true, "str %s", toString());
+
+ // Flagged but not auto-fixed.
+ checkArgument(true, "%s " + toString(), "arg");
+ }
+
+ void jdk() {
+ String.format("str %s", toString());
+ String.format(Locale.ROOT, "str %s", toString());
+
+ // Flagged but not auto-fixed.
+ String.format("{} " + toString(), "arg");
+ String.format(Locale.ROOT, "{} " + toString(), "arg");
+ }
+
+ void slf4j() {
+ LOG.debug("str {}", toString());
+ LOG.debug((Marker) null, "str {}", toString());
+
+ // Flagged but not auto-fixed.
+ LOG.debug("{} " + toString(), "arg");
+ LOG.debug((Marker) null, "{} " + toString(), "arg");
+ }
+ }
+ """)
.doTest(TestMode.TEXT_MATCH);
}
}
diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java
index f9286f4e73..184424f186 100644
--- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java
+++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java
@@ -12,174 +12,176 @@ void identification() {
CompilationTestHelper.newInstance(IdentityConversion.class, getClass())
.addSourceLines(
"A.java",
- "import static com.google.errorprone.matchers.Matchers.instanceMethod;",
- "import static com.google.errorprone.matchers.Matchers.staticMethod;",
- "",
- "import com.google.common.collect.ImmutableBiMap;",
- "import com.google.common.collect.ImmutableList;",
- "import com.google.common.collect.ImmutableListMultimap;",
- "import com.google.common.collect.ImmutableMap;",
- "import com.google.common.collect.ImmutableMultimap;",
- "import com.google.common.collect.ImmutableMultiset;",
- "import com.google.common.collect.ImmutableRangeMap;",
- "import com.google.common.collect.ImmutableRangeSet;",
- "import com.google.common.collect.ImmutableSet;",
- "import com.google.common.collect.ImmutableSetMultimap;",
- "import com.google.common.collect.ImmutableTable;",
- "import com.google.errorprone.matchers.Matcher;",
- "import com.google.errorprone.matchers.Matchers;",
- "import java.time.Instant;",
- "import java.time.ZonedDateTime;",
- "import reactor.adapter.rxjava.RxJava2Adapter;",
- "import reactor.core.publisher.Flux;",
- "import reactor.core.publisher.Mono;",
- "",
- "public final class A {",
- " public void m() {",
- " // BUG: Diagnostic contains:",
- " Boolean b1 = Boolean.valueOf(Boolean.FALSE);",
- " // BUG: Diagnostic contains:",
- " Boolean b2 = Boolean.valueOf(false);",
- " // BUG: Diagnostic contains:",
- " boolean b3 = Boolean.valueOf(Boolean.FALSE);",
- " // BUG: Diagnostic contains:",
- " boolean b4 = Boolean.valueOf(false);",
- "",
- " // BUG: Diagnostic contains:",
- " Byte byte1 = Byte.valueOf((Byte) Byte.MIN_VALUE);",
- " // BUG: Diagnostic contains:",
- " Byte byte2 = Byte.valueOf(Byte.MIN_VALUE);",
- " // BUG: Diagnostic contains:",
- " byte byte3 = Byte.valueOf((Byte) Byte.MIN_VALUE);",
- " // BUG: Diagnostic contains:",
- " byte byte4 = Byte.valueOf(Byte.MIN_VALUE);",
- "",
- " // BUG: Diagnostic contains:",
- " Character c1 = Character.valueOf((Character) 'a');",
- " // BUG: Diagnostic contains:",
- " Character c2 = Character.valueOf('a');",
- " // BUG: Diagnostic contains:",
- " char c3 = Character.valueOf((Character) 'a');",
- " // BUG: Diagnostic contains:",
- " char c4 = Character.valueOf('a');",
- "",
- " // BUG: Diagnostic contains:",
- " Double d1 = Double.valueOf((Double) 0.0);",
- " // BUG: Diagnostic contains:",
- " Double d2 = Double.valueOf(0.0);",
- " // BUG: Diagnostic contains:",
- " double d3 = Double.valueOf((Double) 0.0);",
- " // BUG: Diagnostic contains:",
- " double d4 = Double.valueOf(0.0);",
- "",
- " // BUG: Diagnostic contains:",
- " Float f1 = Float.valueOf((Float) 0.0F);",
- " // BUG: Diagnostic contains:",
- " Float f2 = Float.valueOf(0.0F);",
- " // BUG: Diagnostic contains:",
- " float f3 = Float.valueOf((Float) 0.0F);",
- " // BUG: Diagnostic contains:",
- " float f4 = Float.valueOf(0.0F);",
- "",
- " // BUG: Diagnostic contains:",
- " Integer i1 = Integer.valueOf((Integer) 1);",
- " // BUG: Diagnostic contains:",
- " Integer i2 = Integer.valueOf(1);",
- " // BUG: Diagnostic contains:",
- " int i3 = Integer.valueOf((Integer) 1);",
- " // BUG: Diagnostic contains:",
- " int i4 = Integer.valueOf(1);",
- "",
- " // BUG: Diagnostic contains:",
- " Long l1 = Long.valueOf((Long) 1L);",
- " // BUG: Diagnostic contains:",
- " Long l2 = Long.valueOf(1L);",
- " // BUG: Diagnostic contains:",
- " long l3 = Long.valueOf((Long) 1L);",
- " // BUG: Diagnostic contains:",
- " long l4 = Long.valueOf(1L);",
- "",
- " Long l5 = Long.valueOf((Integer) 1);",
- " Long l6 = Long.valueOf(1);",
- " // BUG: Diagnostic contains:",
- " long l7 = Long.valueOf((Integer) 1);",
- " // BUG: Diagnostic contains:",
- " long l8 = Long.valueOf(1);",
- "",
- " // BUG: Diagnostic contains:",
- " Short s1 = Short.valueOf((Short) Short.MIN_VALUE);",
- " // BUG: Diagnostic contains:",
- " Short s2 = Short.valueOf(Short.MIN_VALUE);",
- " // BUG: Diagnostic contains:",
- " short s3 = Short.valueOf((Short) Short.MIN_VALUE);",
- " // BUG: Diagnostic contains:",
- " short s4 = Short.valueOf(Short.MIN_VALUE);",
- "",
- " // BUG: Diagnostic contains:",
- " String boolStr = Boolean.valueOf(Boolean.FALSE).toString();",
- " int boolHash = Boolean.valueOf(false).hashCode();",
- " // BUG: Diagnostic contains:",
- " int byteHash = Byte.valueOf((Byte) Byte.MIN_VALUE).hashCode();",
- " String byteStr = Byte.valueOf(Byte.MIN_VALUE).toString();",
- "",
- " String str1 = String.valueOf(0);",
- " // BUG: Diagnostic contains:",
- " String str2 = String.valueOf(\"1\");",
- "",
- " // BUG: Diagnostic contains:",
- " ImmutableBiMap