New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix crash in ajava-based WPI related to captures #5335
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4c5570c
non-minimized test case demonstrating the crash
kelloggm 6366b2e
minimize the test and a sketchy fix
kelloggm abf3c8f
Merge branch 'master' into wpi-classcast-crash-icse
kelloggm ef3942b
Remove new line.
smillst 515da1d
debug code
kelloggm f4131a3
fix wording
kelloggm 11807c5
Add new test case.
smillst eeff63b
Merge branch 'master' of https://github.com/typetools/checker-framewo…
kelloggm 4174583
better fix based on Suzanne's insight
kelloggm 7787d46
fix a bug I'd introduced with respect to nullness handling, which als…
kelloggm File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
checker/tests/ainfer-index/non-annotated/Dataset6Crash.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,57 @@ | ||
// Test case for a WPI crash caused by mismatches between captured type variables | ||
// and the declared type of a field: in particular, the issue is that base.next() | ||
// the next field actually have slightly different types: base.next()'s type is | ||
// a capture that extends T. | ||
|
||
import java.util.Iterator; | ||
|
||
public class Dataset6Crash { | ||
|
||
public static <T> Iterator<T> limit(final Iterator<? extends T> base, final CountingPredicate<? | ||
super T> filter) { | ||
return new Iterator<T>() { | ||
|
||
private T next; | ||
|
||
private boolean end; | ||
|
||
private int index = 0; | ||
|
||
public boolean hasNext() { | ||
return true; | ||
} | ||
|
||
public T next() { | ||
fetch(); | ||
T r = next; | ||
next = null; | ||
return r; | ||
} | ||
|
||
private void fetch() { | ||
if (next == null && !end) { | ||
if (base.hasNext()) { | ||
next = base.next(); | ||
if (!filter.apply(index++, next)) { | ||
next = null; | ||
end = true; | ||
} | ||
} else { | ||
end = true; | ||
} | ||
} | ||
} | ||
|
||
public void remove() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
}; | ||
} | ||
|
||
|
||
private static class CountingPredicate<T> { | ||
public boolean apply(int i, T next) { | ||
return false; | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
checker/tests/ainfer-index/non-annotated/TypeVarAssignment.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,6 @@ | ||
public class TypeVarAssignment<T, S extends T> { | ||
T t; | ||
void foo(S s) { | ||
t = s; | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem isn't a
AnnotatedDeclaredType
with an underlying type ofTYPEVAR
, it's whenupdateAtmWithLub
recurs on the upper bounds of the type var, they may not be the same kind of type. This happens with capture conversion, but also two type variables. See the test case I added.Hopefully using that information you can fix the problem, rather than catching the exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You were exactly right - thanks for figuring this out! I'm glad there wasn't a deeper problem, and I've now written a proper fix.