-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make synthetic classes used in a try with resources statement impleme…
…nt AutoCloseable (#337) Based on a problem I noticed while investigating why Specimin wasn't handling na-176 properly. There are probably other issues with that bug, but this one seemed like a good place to start.
- Loading branch information
Showing
10 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/test/java/org/checkerframework/specimin/TryWithResourcesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.checkerframework.specimin; | ||
|
||
import java.io.IOException; | ||
import org.junit.Test; | ||
|
||
/** | ||
* This test checks that an unsolved type that's used in a try-with-resources context correctly | ||
* implements AutoCloseable. | ||
*/ | ||
public class TryWithResourcesTest { | ||
@Test | ||
public void runTest() throws IOException { | ||
SpeciminTestExecutor.runTestWithoutJarPaths( | ||
"trywithresources", | ||
new String[] {"com/example/Simple.java"}, | ||
new String[] {"com.example.Simple#bar(OtherResource)"}); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/resources/trywithresources/expected/com/example/Simple.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.example; | ||
|
||
import org.example.Resource; | ||
import org.example.OtherResource; | ||
import org.example.ThirdResource; | ||
|
||
class Simple { | ||
|
||
private final ThirdResource r = null; | ||
|
||
void bar(final OtherResource o) throws Exception { | ||
try (Resource r = new Resource()) { | ||
} | ||
try (o) { | ||
} | ||
try (r) { | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/test/resources/trywithresources/expected/org/example/OtherResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.example; | ||
|
||
public class OtherResource implements java.lang.AutoCloseable { | ||
|
||
public void close() throws java.lang.Exception { | ||
throw new Error(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/resources/trywithresources/expected/org/example/Resource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.example; | ||
|
||
public class Resource implements java.lang.AutoCloseable { | ||
|
||
public Resource() { | ||
throw new Error(); | ||
} | ||
|
||
public void close() throws java.lang.Exception { | ||
throw new Error(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/test/resources/trywithresources/expected/org/example/ThirdResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.example; | ||
|
||
public class ThirdResource implements java.lang.AutoCloseable { | ||
|
||
public void close() throws java.lang.Exception { | ||
throw new Error(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/test/resources/trywithresources/input/com/example/Simple.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.example; | ||
|
||
import org.example.Resource; | ||
import org.example.OtherResource; | ||
import org.example.ThirdResource; | ||
|
||
class Simple { | ||
|
||
private final ThirdResource r = null; | ||
|
||
// Target method. | ||
void bar(final OtherResource o) throws Exception { | ||
try (Resource r = new Resource()) { | ||
// do something | ||
} | ||
try (o) { | ||
// do something else | ||
} | ||
try (r) { | ||
|
||
} | ||
} | ||
} |