Skip to content
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

refactor: Resolving unchecked-cast warnings in ContractVerifier #6173

Conversation

rishivijayv
Copy link
Contributor

#4924

Not entirely sure if this is an acceptable fix because I don't feel too good about using SuppressWarnings here (and we generally seem to be against doing that as seen in #4925), but the unchecked cast issue here was caused by (Collection<CtElement>) attributeOfParent... and (Map<String, ?>) attributeOfParent.

I wasn't sure how to go about fixing these, since they weren't really related to returning this or super.clone() and a quick Google search wasn't helpful either (giving suggestions such as this)-- so I'm more than open to alternative ways of fixing this, if there are any!

Before

These 2 Warnings appeared when running mvn compile after a clean

...
[WARNING] .../ContractVerifier.java:[567,90] unchecked cast
  required: java.util.Collection<spoon.reflect.declaration.CtElement>
  found:    java.lang.Object
[WARNING] .../ContractVerifier.java:[572,83] unchecked cast
  required: java.util.Map<java.lang.String,?>
  found:    java.lang.Object
...

After

Those 2 warnings are gone! :)

@SirYwell would appreciate your thoughts on this, since I believe you've been involved with the effort in clearing out unchecked-cast warnings before 😅

@SirYwell
Copy link
Collaborator

SirYwell commented Feb 5, 2025

I think both warnings can also be avoided by just using wildcard generics instead of concrete types. For the first one, == will still work, and for the second one, the type we operate on already is ?, just the String causes the warning - but we never need that at all.

@rishivijayv
Copy link
Contributor Author

@SirYwell Ohh that's great! Updated the changes and the warnings are gone now even without SuppressWarning 😄

I'll have to look in to wildcard generics a little more as my knowledge of those is still a little flaky, but thanks for the tip! 🫡

Copy link
Collaborator

@SirYwell SirYwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good.

@SirYwell SirYwell merged commit c59c903 into INRIA:master Feb 8, 2025
13 checks passed
@rishivijayv rishivijayv deleted the refactor/resolve-unchecked-cast-contract-verifier branch February 8, 2025 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants