-
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.
Add guardrails to prevent and correct wrong output from JavaTypeCorre…
…ct (#339) ~~Incorporates #338, so don't review until that is merged.~~ ~~I'm not sure if we want to merge this. It avoids some bad behavior on the NA-176 test, and we could probably expand it in the future for other, similar kinds of problems. However, it definitely does not address the root cause: why is Specimin putting itself in a situation where javac insists that a synthetic class must be compatible with String?~~ ~~I'm going to continue my investigation, but I'm leaving this PR here because I may want to merge it later if the fix for the root cause is too complex and/or impracticle.~~ This PR makes a series of changes to how our javac type correction algorithm (in the `JavaTypeCorrect` class) handles complex cases. That algorithm is fundamentally imprecise, so the changes in this PR should be thought of as incremental improvements to the existing design that avoid some of its worst pathologies. In particular, this PR: * prevents JavaTypeCorrect from ever attempting to make a class extend `java.lang.String`, which is final; * makes it generally more difficult for the `SyntheticUnconstrainedType` type variable to propagate beyond the return type to which it is applied; and, * replaces parameters whose types are synthetic return types that get replaced by `SyntheticUnconstrainedType` with `java.lang.Object`. Previously, these types would hang around and make the output non-compilable, since they'd been marked as unused. Together, these changes make NullAway-176 reproducible, based on my local testing.
- Loading branch information
Showing
15 changed files
with
215 additions
and
19 deletions.
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
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/WhenThenTest.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 typically-styled test code doesn't cause Specimin to lose a method. Based | ||
* on a bug observed in na-176. | ||
*/ | ||
public class WhenThenTest { | ||
@Test | ||
public void runTest() throws IOException { | ||
SpeciminTestExecutor.runTestWithoutJarPaths( | ||
"whenthen", | ||
new String[] {"com/example/Simple.java"}, | ||
new String[] {"com.example.Simple#bar()"}); | ||
} | ||
} |
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,4 @@ | ||
package com.example; | ||
|
||
public class Banana { | ||
} |
16 changes: 16 additions & 0 deletions
16
src/test/resources/whenthen/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,16 @@ | ||
package com.example; | ||
|
||
import static org.example.TestUtil.when; | ||
import static org.example.TestUtil.mock; | ||
|
||
import com.example.Banana; | ||
|
||
class Simple { | ||
|
||
void bar() { | ||
Integer s = mock(2); | ||
Banana b = mock(3); | ||
when(5).then("Foo"); | ||
when("bar").then(mock(1)); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/resources/whenthen/expected/org/example/OrgExampleTestUtilWhenReturnType.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 OrgExampleTestUtilWhenReturnType { | ||
|
||
public ThenReturnType then(java.lang.String parameter0) { | ||
throw new Error(); | ||
} | ||
|
||
public ThenReturnType then(java.lang.Object parameter0) { | ||
throw new Error(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/test/resources/whenthen/expected/org/example/TestUtil.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,16 @@ | ||
package org.example; | ||
|
||
public class TestUtil { | ||
|
||
public static <SyntheticUnconstrainedType> SyntheticUnconstrainedType mock(int parameter0) { | ||
throw new Error(); | ||
} | ||
|
||
public static OrgExampleTestUtilWhenReturnType when(int parameter0) { | ||
throw new Error(); | ||
} | ||
|
||
public static OrgExampleTestUtilWhenReturnType when(java.lang.String parameter0) { | ||
throw new Error(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/test/resources/whenthen/expected/org/example/ThenReturnType.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,4 @@ | ||
package org.example; | ||
|
||
public class ThenReturnType { | ||
} |
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,16 @@ | ||
package com.example; | ||
|
||
import static org.example.TestUtil.when; | ||
import static org.example.TestUtil.mock; | ||
|
||
import com.example.Banana; | ||
|
||
class Simple { | ||
|
||
void bar() { | ||
Integer s = mock(2); | ||
Banana b = mock(3); | ||
when(5).then("Foo"); | ||
when("bar").then(mock(1)); | ||
} | ||
} |