A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/4435 below:

[java] [7.0-rc1] UnusedAssignment for used field · Issue #4435 · pmd/pmd · GitHub

Affects PMD Version:
7.0-rc1 when upgrading from 6.55

Rule:
UnusedAssignment

Description:
A class field is not the same as a method variable as it is in scope for other method calls. This also only restores the value when an unhandled error occurs to rollback the state, so the detection is misunderstanding the behavior.

Code Sample demonstrating the issue:

public void advance(BoundedLocalCache<K, V> cache, long currentTimeNanos) {
  long previousTimeNanos = nanos;
  nanos = currentTimeNanos;

  try {
    // ...
  } catch (Throwable t) {
    nanos = previousTimeNanos;
    throw t;
  }
}

Expected outcome:
PMD reports a violation but that should not apply to a class field.

# File Line Problem 1 TimerWheel.java 90 The value assigned to field 'nanos' is never used (overwritten on line 111)

Running PMD through: Gradle
This requires workaround in gradle/gradle#24502


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4