Skip to content

Commit 4f060e1

Browse files
klueverError Prone Team
authored andcommitted
Add a test case demonstrating a CanIgnoreReturnValueSuggester bug.
PiperOrigin-RevId: 607088772
1 parent a1f4fa7 commit 4f060e1

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

core/src/test/java/com/google/errorprone/bugpatterns/checkreturnvalue/CanIgnoreReturnValueSuggesterTest.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,4 +924,49 @@ public void anonymous() {
924924
.expectUnchanged()
925925
.doTest();
926926
}
927+
928+
@Test
929+
public void returningANewInstance() {
930+
helper
931+
.addInputLines(
932+
"MyBuilder.java",
933+
"public final class MyBuilder {",
934+
" MyBuilder() { }",
935+
" MyBuilder(String name) { }",
936+
" MyBuilder(MyBuilder builder) { }",
937+
" public MyBuilder passingParam(String name) {",
938+
" return new MyBuilder(name);",
939+
" }",
940+
" public MyBuilder passingThis() {",
941+
" return new MyBuilder(this);",
942+
" }",
943+
" public MyBuilder notPassing() {",
944+
" return new MyBuilder();",
945+
" }",
946+
"}")
947+
.addOutputLines(
948+
"MyBuilder.java",
949+
"import com.google.errorprone.annotations.CanIgnoreReturnValue;",
950+
"public final class MyBuilder {",
951+
" MyBuilder() { }",
952+
" MyBuilder(String name) { }",
953+
" MyBuilder(MyBuilder builder) { }",
954+
// TODO(b/325282579): this is a bug! we should not recommend @CIRV here!
955+
" @CanIgnoreReturnValue",
956+
" public MyBuilder passingParam(String name) {",
957+
" return new MyBuilder(name);",
958+
" }",
959+
// TODO(b/325282579): this is a bug! we should not recommend @CIRV here!
960+
" @CanIgnoreReturnValue",
961+
" public MyBuilder passingThis() {",
962+
" return new MyBuilder(this);",
963+
" }",
964+
// TODO(b/325282579): this is a bug! we should not recommend @CIRV here!
965+
" @CanIgnoreReturnValue",
966+
" public MyBuilder notPassing() {",
967+
" return new MyBuilder();",
968+
" }",
969+
"}")
970+
.doTest();
971+
}
927972
}

0 commit comments

Comments
 (0)