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
Conversation
Are you saying there's an |
updateAtmWithLub(rhsATM, atmFromStorage); | ||
// It is possible that rhsATM is a type variable but atmFromStorage is not, which | ||
// would cause a ClassCastException in updateAtmWithLub(). This can | ||
// happen for example when a local variable of type ? extends T is assigned to a |
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.
A local variable can't have a wildcard type. I think you when an expression has type ? extends T
.
I think that is what's happening. I've added debug code to the
I have no idea where the bad |
updateAtmWithLub(rhsATM, atmFromStorage); | ||
} catch (ClassCastException c) { | ||
System.out.println("Catching a ClassCastException: " + c); | ||
System.out.println( |
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 of TYPEVAR
, it's when updateAtmWithLub
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.
… into wpi-classcast-crash-icse
…o makes a prior check unnecessary
@smillst I'll need you to review this again: the tests for the version you approved earlier today failed for a good reason: the check did the wrong thing if one of the arguments to |
I'm fairly confident that there is a better way to do this than catching the
ClassCastException
, but I was worried of the performance implications of callingasSuper
on every inference of a field's type, since only very rarely will the twoAnnotatedTypeMirror
not actually have the same actual Java class (causing the exception).Technically, their
kind
is the same - they are both typevars - so it cannot be checked that way, even though the underlying Java class of one isAnnotatedDeclaredType
. I think it's probably bad thatupdateAtmWithLub
directly casts toAnnotatedTypeVariable
, but I'm not sure how else it could work.