IntelliJ 2018.1 highlights that 'val' variables should have 'final' modifier
See original GitHub issueShort 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
- Enable inspection ‘Local variable or parameter can be final’ in IDE
- Create Java class with any method containing something like val x = new Object();
- IDE highlights variable ‘x’ as not having ‘final’ modifier. (See also attached screenshot)
Sample project
Please provide a sample project that exhibits the problem.
You should also include .idea
folder so we can inspect the settings.
- Sample project provided valissue.zip
- I am able to reproduce this error on the sample project by following the steps described above
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:12 (2 by maintainers)
Top Results From Across the Web
Auto-add the "final" modifier to newly declared variables/values
Non-final vars will get warning gighlighting. Naviagate to any and press Alt+Enter. At 'Accept Suggested Final Modifier' press Right arrow and ...
Read more >IntelliJ IDEA 2018.1 2018.1 Release Notes | Knowledge Base
Bug, IDEA-185066, method should not be highlighted redundant ... Bug, IDEA-170073, False positive 'Declaration can have final modifier'.
Read more >IntelliJ IDEA 2018.1 Release Notes | Knowledge Base
Feature IDEA‑152725 Extend templating language to expose outer class
Feature IDEA‑143537 Allow line breaks in scope patterns
Feature IDEA‑76704 Make "Show in Explorer" work from...
Read more >IntelliJ IDEA 2018.1 181.2784.17 Release Notes - YouTrack
Feature, IDEA-184299, Warn if variable is assigned to the value which it already ... Bug, IDEA-170073, False positive 'Declaration can have final modifier'....
Read more >IntelliJ IDEA 2018.2 Release Notes | Knowledge Base
Feature IDEA‑188431 Better completion variants in Stream::toArray() method
Feature IDEA‑143537 Allow line breaks in scope patterns
Feature IDEA‑190682 Support multi ip hosts in client‑api RpcUtils
Bug...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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 thefinal
keyword beforeval
which was definitely not the case before.