Skip to content

Commit 266a16e

Browse files
cushonError Prone Team
authored and
Error Prone Team
committed
Cleanup a test that was relying on https://bugs.openjdk.java.net/browse/JDK-8293897
PiperOrigin-RevId: 478920369
1 parent dd4b8dc commit 266a16e

File tree

3 files changed

+83
-34
lines changed

3 files changed

+83
-34
lines changed

core/src/test/java/com/google/errorprone/bugpatterns/MustBeClosedCheckerTest.java

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.errorprone.BugCheckerRefactoringTestHelper;
2020
import com.google.errorprone.CompilationTestHelper;
21+
import org.junit.Ignore;
2122
import org.junit.Test;
2223
import org.junit.runner.RunWith;
2324
import org.junit.runners.JUnit4;
@@ -72,4 +73,86 @@ public void enumInitializer() {
7273
"}")
7374
.doTest();
7475
}
76+
77+
@Test
78+
public void forLoop() {
79+
refactoringHelper
80+
.addInputLines(
81+
"Test.java",
82+
"import com.google.errorprone.annotations.MustBeClosed;",
83+
"class Test {",
84+
" class Closeable implements AutoCloseable {",
85+
" @Override",
86+
" public void close() {}",
87+
" public int method() {",
88+
" return 1;",
89+
" }",
90+
" }",
91+
" class Foo {",
92+
" @MustBeClosed",
93+
" Closeable mustBeClosedMethod() {",
94+
" return null;",
95+
" }",
96+
" }",
97+
" void forLoopCondition() {",
98+
" for (int i = 0; i < new Foo().mustBeClosedMethod().method(); ++i) {}",
99+
" }",
100+
"}")
101+
.addOutputLines(
102+
"Test.java",
103+
"import com.google.errorprone.annotations.MustBeClosed;",
104+
"class Test {",
105+
" class Closeable implements AutoCloseable {",
106+
" @Override",
107+
" public void close() {}",
108+
" public int method() {",
109+
" return 1;",
110+
" }",
111+
" }",
112+
" class Foo {",
113+
" @MustBeClosed",
114+
" Closeable mustBeClosedMethod() {",
115+
" return null;",
116+
" }",
117+
" }",
118+
" void forLoopCondition() {",
119+
" try (var closeable = new Foo().mustBeClosedMethod()) {",
120+
" for (int i = 0; i < closeable.method(); ++i) {}",
121+
" }",
122+
" }",
123+
"}")
124+
.doTest();
125+
}
126+
127+
@Ignore("b/236715080")
128+
@Test
129+
public void forLoopUnfixable() {
130+
refactoringHelper
131+
.addInputLines(
132+
"Test.java",
133+
"import com.google.errorprone.annotations.MustBeClosed;",
134+
"class Test {",
135+
" class Closeable implements AutoCloseable {",
136+
" @Override",
137+
" public void close() {}",
138+
" public int method() {",
139+
" return 1;",
140+
" }",
141+
" }",
142+
" class Foo {",
143+
" @MustBeClosed",
144+
" Closeable mustBeClosedMethod() {",
145+
" return null;",
146+
" }",
147+
" }",
148+
" void forLoopInitialization() {",
149+
" for (int i = new Foo().mustBeClosedMethod().method(); i > 0; --i) { }",
150+
" }",
151+
" void forLoopUpdate() {",
152+
" for (int i = 0; i < 100; i += new Foo().mustBeClosedMethod().method()) {}",
153+
" }",
154+
"}")
155+
.expectUnchanged()
156+
.doTest();
157+
}
75158
}

core/src/test/java/com/google/errorprone/bugpatterns/testdata/MustBeClosedCheckerPositiveCases.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,6 @@ int variableDeclaration() {
172172
return result;
173173
}
174174

175-
void forLoopInitialization() {
176-
// TODO(b/236715080): fix results in invalid code. BUG: Diagnostic contains:
177-
// for (int i = new Foo().mustBeClosedAnnotatedMethod().method(); i > 0; --i) { }
178-
}
179-
180-
void forLoopConditionUnfixable() {
181-
// TODO(b/236715080): suggested fix changes behavior.
182-
// BUG: Diagnostic contains:
183-
for (int i = 0; i < new Foo().mustBeClosedAnnotatedMethod().method(); ++i) {}
184-
}
185-
186-
void forLoopUpdateUnfixable() {
187-
// TODO(b/236715080): fix results in invalid code. BUG: Diagnostic contains:
188-
// for (int i = 0; i < 100; i += new Foo().mustBeClosedAnnotatedMethod().method()) {}
189-
}
190-
191175
void tryWithResources_nonFinal() {
192176
Foo foo = new Foo();
193177
// BUG: Diagnostic contains:

core/src/test/java/com/google/errorprone/bugpatterns/testdata/MustBeClosedCheckerPositiveCases_expected.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -188,24 +188,6 @@ int variableDeclaration() {
188188
return result;
189189
}
190190

191-
void forLoopInitialization() {
192-
// TODO(b/236715080): fix results in invalid code. BUG: Diagnostic contains:
193-
// for (int i = new Foo().mustBeClosedAnnotatedMethod().method(); i > 0; --i) {}
194-
}
195-
196-
void forLoopConditionUnfixable() {
197-
// TODO(b/236715080): suggested fix changes behavior.
198-
// BUG: Diagnostic contains:
199-
try (final var closeable = new Foo().mustBeClosedAnnotatedMethod()) {
200-
for (int i = 0; i < closeable.method(); ++i) {}
201-
}
202-
}
203-
204-
void forLoopUpdateUnfixable() {
205-
// TODO(b/236715080): fix results in invalid code. BUG: Diagnostic contains:
206-
// for (int i = 0; i < 100; i += new Foo().mustBeClosedAnnotatedMethod().method()) {}
207-
}
208-
209191
void tryWithResources_nonFinal() {
210192
Foo foo = new Foo();
211193
// BUG: Diagnostic contains:

0 commit comments

Comments
 (0)