Lombok-intellij-plugin: IntelliJ 2018.1 highlights that 'val' variables should have 'final' modifier

Created on 30 Mar 2018  路  12Comments  路  Source: mplushnikov/lombok-intellij-plugin

Short description

After upgrade to IntelliJ 2018.1 and latest Lombok Plugin available from plugin repository I'm getting IDE highlights on variables marked with 'val', that they don't have 'final' modifier (IDEA inspection 'Local variable or parameter can be final').

Expected behavior

No variable highlighting and IDE correctly reads 'val' as having 'final' modifier.

Version information

  • IDEA Version: IntelliJ IDEA 2018.1 (Ultimate Edition)
    Build #IU-181.4203.550, built on March 27, 2018
  • JDK Version: Oracle JDK 1.8.0_152
  • OS Type & Version: both Win10 and Win7
  • Lombok Plugin Version: 0.17-2018.1
  • Lombok Dependency Version: 1.16.20

Steps to reproduce

  1. Enable inspection 'Local variable or parameter can be final' in IDE
  2. Create Java class with any method containing something like
    val x = new Object();
  3. IDE highlights variable 'x' as not having 'final' modifier. (See also attached screenshot)
    valissue example

Sample project

Please provide a sample project that exhibits the problem.
You should also include .idea folder so we can inspect the settings.

  • [x] Sample project provided
    valissue.zip
  • [ ] I am able to reproduce this error on the sample project by following the steps described above
needIntellijDeveloperSupport

All 12 comments

Check this.

Thanks for the suggestion, but unfortunately it didn't help.
Original problem remains: IDEA still displays same highlights for plugin installed from disk.
'Invalidate caches & Restart' after plugin re-install didn't help either.

Just to clarify: there are neither compilation problems, nor any errors when working with vals in code. Just false-positive warnings from IDE about missing finals.

I experience the same problem. Unfortunately, this also leads to other problems when using lombok's val in combination with other plugins like "SaveActions" that seem to rely on the suggestions offered by IntelliJ. Since the 2018.1 update, SaveActions automatically applies the final keyword before val which was definitely not the case before.

Surprisingly this seems to be a problem in Intellij's inspection which ignores how this plugin "fakes" the final keyword:

https://youtrack.jetbrains.com/issue/IDEA-182740

That's indeed surprising!
Thank you @kossmoboleat :)
As suggested in referenced IDEA issue: disabling "Report variables which are implicit final" under "Local variable or parameter can be final" seems to solve problem.

I'd leave this ticket open for awhile just in case there is possible workaround on lombok plugin side (comment from plugin maintainers will be really appreciated).
If there is no way to update plugin's behavior to work with new IDEA API, then it would OK to close this issue I think.

Yes, the workaround seems to work for the inspection, but it doesn't for usage in combination with the "save actions" plugin, because that one doesn't seem to respect the checkmark.

Also by using this workaround, we're then not getting the correct the correct inspection result for that try-with-resources case mentioned in the youtrack issue. I wrote there again, but I'm also not that knowledgeable if the check I proposed there is the way to go.

@mplushnikov What do you think is the best course of action here? Should we ask the Jetbrains developer to add a new API for this?

It seems to me that one would a new access to the final modifier because the implicit modifier is either ignored in the default setting or it isn't and the linked resource case isn't properly handled.

@mplushnikov Any new thoughts on this?

@kossmoboleat
Nothing special at the moment, just only asked @akozlova about new extension point...

@mplushnikov Ok, the Intellij developer requires some feedback before she continues:
https://youtrack.jetbrains.com/issue/IDEA-182740

@mplushnikov, can you please answer @akozlova on youtrack?

@kossmoboleat I'm very sorry, answered the question only now. There is a lot of work family man:(

Was this page helpful?
0 / 5 - 0 ratings