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

@Getter(lazy=true) causes unchecked cast warning #880

Closed
sgrimm-sg opened this issue Jul 18, 2015 · 8 comments
Closed

@Getter(lazy=true) causes unchecked cast warning #880

sgrimm-sg opened this issue Jul 18, 2015 · 8 comments

Comments

@sgrimm-sg
Copy link

The Lombok-generated code from @getter(lazy=true) contains a cast from Object to the field's type, which causes an unchecked cast warning when compiling with -Xlint:all.

@rspilker
Copy link
Collaborator

There's not a lot we can do here.

We do put two annotations on the method to let the compiler know it shouldn't emit warnings:

  • @java.lang.SuppressWarnings("all")
  • @javax.annotation.Generated("lombok")

The code is fine. Yes, the cast might be unsafe, but the code makes sure it isn't.

@LunNova
Copy link
Contributor

LunNova commented Jan 24, 2016

Is SuppressWarnings definitely being added correctly?

I'm not setting any special lint options using -Xlint:all -Xlint:-processing and warning: [unchecked] unchecked cast is showing up for any use of @Getter(lazy=true).

@sgrimm-sg
Copy link
Author

For what it's worth, here's the workaround we settled on, which gets rid of the warnings.

@Getter(lazy = true, onMethod = @__({@SuppressWarnings("unchecked")}))

@Maaartinus
Copy link
Contributor

Maaartinus commented Oct 8, 2019

@rspilker According to the duplicate thread, adding the "unchecked" token to "all" helps, and it should be rather easy for Lombok to do this. Should I give it a try? Or would you?

There's a minor complication: For primitives, the "unchecked" token produces a warning in eclipse.

@mjustin
Copy link

mjustin commented Jan 30, 2020

@rspilker One wrinkle that makes this a bit more problematic: the onMethod workaround suggested in this thread currently causes an exception in Checkstyle when using the SuppressWarningsFilter, per checkstyle/checkstyle#7522.

@rzwitserloot rzwitserloot reopened this Feb 4, 2020
@rzwitserloot
Copy link
Collaborator

Just to get it on the record: Whomever designed how @SuppressWarnings works should be flogged. What an omnibomb of a disaster. There are no specs, everybody does their own thing, and "all" means so many things... except "all". There is in fact no actual "all" at all. Aaaargh 🤢 💥

Adding "unchecked" helps, yeah. We'll get on that; good point by @Maaartinus that we do need to check if the type is primitive in which case, don't (we already do this, I think; we have to use a different AtomicX if the field is primitive already, and whilst we can't do resolution, primitives are hardcoded concepts we can trivially check for – not complicated in either case).

@rzwitserloot
Copy link
Collaborator

There's a minor complication: For primitives, the "unchecked" token produces a warning in eclipse.

Can't reproduce. We actually cast e.g. (java.lang.Long), letting auto-unboxing do the final step, so hopefully you meant this comment as a more general observation and not specifically for what @Getter(lazy=true) does.

@rzwitserloot
Copy link
Collaborator

Live in 1.18.12.

Febell pushed a commit to Febell/lombok that referenced this issue Mar 1, 2020
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

No branches or pull requests

6 participants