Quickfix of S1068 can introduce a compilation error

  • Operating system: Ubuntu 22.04LTS
  • IDE name and flavor/env: IntelliJ IDEA version 2022.2.3
  • SonarLint version:

Consider the following snippet,

public class PrivateFieldWrittenButNotRead {
    private int x;

    public PrivateFieldWrittenButNotRead(int x, int y) {
        this.x = x + y;

Field x is marked as unused as it violates S1068 and SonarLint also has a quickfix for it. However, if the quickfix is accepted, compilation error is introduced because of the statement inside the constructor.

A better fix would also be to remove all writes to the field.

Hello @aman,

Thanks for your message. Indeed, if you just apply the quick fix as is without further processing, the code won’t compile. The initial idea was to remove the initialization (as the issue is reported correctly) and then let the developer do the rest.

And I agree, there is a space for improvement here. So here is the ticket to improve the quick fix:



1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.