Skip to content

Commit

Permalink
Add a test case demonstrating a CanIgnoreReturnValueSuggester bug.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 607088772
  • Loading branch information
kluever authored and Error Prone Team committed Feb 14, 2024
1 parent a1f4fa7 commit 4f060e1
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -924,4 +924,49 @@ public void anonymous() {
.expectUnchanged()
.doTest();
}

@Test
public void returningANewInstance() {
helper
.addInputLines(
"MyBuilder.java",
"public final class MyBuilder {",
" MyBuilder() { }",
" MyBuilder(String name) { }",
" MyBuilder(MyBuilder builder) { }",
" public MyBuilder passingParam(String name) {",
" return new MyBuilder(name);",
" }",
" public MyBuilder passingThis() {",
" return new MyBuilder(this);",
" }",
" public MyBuilder notPassing() {",
" return new MyBuilder();",
" }",
"}")
.addOutputLines(
"MyBuilder.java",
"import com.google.errorprone.annotations.CanIgnoreReturnValue;",
"public final class MyBuilder {",
" MyBuilder() { }",
" MyBuilder(String name) { }",
" MyBuilder(MyBuilder builder) { }",
// TODO(b/325282579): this is a bug! we should not recommend @CIRV here!
" @CanIgnoreReturnValue",
" public MyBuilder passingParam(String name) {",
" return new MyBuilder(name);",
" }",
// TODO(b/325282579): this is a bug! we should not recommend @CIRV here!
" @CanIgnoreReturnValue",
" public MyBuilder passingThis() {",
" return new MyBuilder(this);",
" }",
// TODO(b/325282579): this is a bug! we should not recommend @CIRV here!
" @CanIgnoreReturnValue",
" public MyBuilder notPassing() {",
" return new MyBuilder();",
" }",
"}")
.doTest();
}
}

0 comments on commit 4f060e1

Please sign in to comment.