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

Don't emit @SafeVarargs for reifiable types #71

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bndbsh
Copy link
Contributor

@bndbsh bndbsh commented Apr 19, 2019

Attempt to detect if a type is reifiable, and omit the annotation in
those cases.

https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html

However one problem as noted in the comments is we can't get at a
ParameterizedTypeName's enclosing type. So for instance, this code will
treat Foo<X>.Bar as reifiable, even though it isn't.

One idea to get around it would be to toString() the type and check if
it contains any type parameters, although that seems kinda messy.

Attempt to detect if a type is reifiable, and omit the annotation in
those cases.

https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html

However one problem as noted in the comments is we can't get at a
ParameterizedTypeName's enclosing type. So for instance, this code will
treat `Foo<X>.Bar` as reifiable, even though it isn't.

One idea to get around it would be to `toString()` the type and check if
it contains any type parameters, although that seems kinda messy.
@lepistone
Copy link

Hi! Giving a look at how java.util.List.of() is implemented, could we just do the same that they do and generate always the following?

@SafeVarargs
@SuppressWarnings("varargs")

@danielnorberg
Copy link
Owner

danielnorberg commented May 20, 2019

@lepistone That indeed seems like a simpler approach. 👍

@danielnorberg
Copy link
Owner

Would using @SuppressWarnings("varargs") help in this case though? Adding it to a method with a reifiable vararg parameter does not seem to make IntelliJ happier about the method.

Javac with -Xlint:all does not emit any warning about @SafeVarargs either way. Is there some static analysis tool that does complain (other than IntelliJ)?

@lepistone
Copy link

@danielnorberg in my case, with Java 11, Javac with -Xlint:all does emit warnings, and auto-matter is the only reason why I have to pass -XLint:-varargs to maven-compiler-plugin. So this is not about intelliJ. I wonder why I get this warning and you don't.

@danielnorberg
Copy link
Owner

@lepistone Indeed. I had simply failed to enable showWarnings.

#72

@danielnorberg
Copy link
Owner

Although the @SuppressWarnings("varargs") has been released in 0.15.3, I guess it could still be neat to avoid both @SafeVarargs and @SuppressWarnings in code generated for reifiable types.

@danielnorberg
Copy link
Owner

danielnorberg commented May 21, 2019

@bndbsh I attempted to handle nested types here, please take a look: bndbsh#1

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.

3 participants