gradle-baseline
gradle-baseline copied to clipboard
StrictUnusedVariable stuck on field that's assigned to but never read
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.