Skip to content

Commit

Permalink
Cleanup a test that was relying on https://bugs.openjdk.java.net/brow…
Browse files Browse the repository at this point in the history
…se/JDK-8293897

PiperOrigin-RevId: 478920369
  • Loading branch information
cushon authored and Error Prone Team committed Oct 5, 2022
1 parent dd4b8dc commit 266a16e
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.errorprone.BugCheckerRefactoringTestHelper;
import com.google.errorprone.CompilationTestHelper;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -72,4 +73,86 @@ public void enumInitializer() {
"}")
.doTest();
}

@Test
public void forLoop() {
refactoringHelper
.addInputLines(
"Test.java",
"import com.google.errorprone.annotations.MustBeClosed;",
"class Test {",
" class Closeable implements AutoCloseable {",
" @Override",
" public void close() {}",
" public int method() {",
" return 1;",
" }",
" }",
" class Foo {",
" @MustBeClosed",
" Closeable mustBeClosedMethod() {",
" return null;",
" }",
" }",
" void forLoopCondition() {",
" for (int i = 0; i < new Foo().mustBeClosedMethod().method(); ++i) {}",
" }",
"}")
.addOutputLines(
"Test.java",
"import com.google.errorprone.annotations.MustBeClosed;",
"class Test {",
" class Closeable implements AutoCloseable {",
" @Override",
" public void close() {}",
" public int method() {",
" return 1;",
" }",
" }",
" class Foo {",
" @MustBeClosed",
" Closeable mustBeClosedMethod() {",
" return null;",
" }",
" }",
" void forLoopCondition() {",
" try (var closeable = new Foo().mustBeClosedMethod()) {",
" for (int i = 0; i < closeable.method(); ++i) {}",
" }",
" }",
"}")
.doTest();
}

@Ignore("b/236715080")
@Test
public void forLoopUnfixable() {
refactoringHelper
.addInputLines(
"Test.java",
"import com.google.errorprone.annotations.MustBeClosed;",
"class Test {",
" class Closeable implements AutoCloseable {",
" @Override",
" public void close() {}",
" public int method() {",
" return 1;",
" }",
" }",
" class Foo {",
" @MustBeClosed",
" Closeable mustBeClosedMethod() {",
" return null;",
" }",
" }",
" void forLoopInitialization() {",
" for (int i = new Foo().mustBeClosedMethod().method(); i > 0; --i) { }",
" }",
" void forLoopUpdate() {",
" for (int i = 0; i < 100; i += new Foo().mustBeClosedMethod().method()) {}",
" }",
"}")
.expectUnchanged()
.doTest();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,6 @@ int variableDeclaration() {
return result;
}

void forLoopInitialization() {
// TODO(b/236715080): fix results in invalid code. BUG: Diagnostic contains:
// for (int i = new Foo().mustBeClosedAnnotatedMethod().method(); i > 0; --i) { }
}

void forLoopConditionUnfixable() {
// TODO(b/236715080): suggested fix changes behavior.
// BUG: Diagnostic contains:
for (int i = 0; i < new Foo().mustBeClosedAnnotatedMethod().method(); ++i) {}
}

void forLoopUpdateUnfixable() {
// TODO(b/236715080): fix results in invalid code. BUG: Diagnostic contains:
// for (int i = 0; i < 100; i += new Foo().mustBeClosedAnnotatedMethod().method()) {}
}

void tryWithResources_nonFinal() {
Foo foo = new Foo();
// BUG: Diagnostic contains:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,6 @@ int variableDeclaration() {
return result;
}

void forLoopInitialization() {
// TODO(b/236715080): fix results in invalid code. BUG: Diagnostic contains:
// for (int i = new Foo().mustBeClosedAnnotatedMethod().method(); i > 0; --i) {}
}

void forLoopConditionUnfixable() {
// TODO(b/236715080): suggested fix changes behavior.
// BUG: Diagnostic contains:
try (final var closeable = new Foo().mustBeClosedAnnotatedMethod()) {
for (int i = 0; i < closeable.method(); ++i) {}
}
}

void forLoopUpdateUnfixable() {
// TODO(b/236715080): fix results in invalid code. BUG: Diagnostic contains:
// for (int i = 0; i < 100; i += new Foo().mustBeClosedAnnotatedMethod().method()) {}
}

void tryWithResources_nonFinal() {
Foo foo = new Foo();
// BUG: Diagnostic contains:
Expand Down

0 comments on commit 266a16e

Please sign in to comment.