gradle-baseline icon indicating copy to clipboard operation
gradle-baseline copied to clipboard

StrictUnusedVariable stuck on field that's assigned to but never read

Open j-baker opened this issue 2 years ago • 0 comments

What happened?

I have some code which I'm trying to keep as identical as possible to some third party code (rewrite of an algorithm in Java).

So, I have a class like (simplified):

public final class ReFairSchedulableBuilder implements ReSchedulableBuilder {
    private final RePool rootPool;
    private final SparkContext sc;

    public ReFairSchedulableBuilder(RePool rootPool, SparkContext sc) {
        this.rootPool = rootPool;
        this.sc = sc;
    }

    @Override
    public void addTaskSetManager(ReTaskSetManager manager, Properties _properties) {
        rootPool.addSchedulable(manager);
    }
}

Here, I get caught by sc being unused. It recommends I should rename it to _sc.

 error: [StrictUnusedVariable] The field 'sc' is never read. Intentional occurrences are acknowledged by renaming the unused variable with a leading underscore. '_sc', for example.

If I apply that fix, I get:

error: [StrictUnusedVariable] The field '_sc' is read but has 'StrictUnusedVariable' suppressed because of its name.
    private final SparkContext _sc;

What did you want to happen?

I cannot see a read of this field (I assume it relates only to a write?). I expected one of the compilations to actually compile! I suppressed the check, but it feels like a bug/edge case/something.

j-baker avatar Aug 03 '22 10:08 j-baker