question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IntelliJ 2018.1 highlights that 'val' variables should have 'final' modifier

See original GitHub issue

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.

  • 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:open
  • Created 5 years ago
  • Reactions:7
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kossmoboleatcommented, May 29, 2018

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.

1reaction
MaximilianWiedemanncommented, May 7, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found