A RetroSearch Logo

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

Search Query:

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

[java] ImmutableField false positive with multiple constructors · Issue #1151 · pmd/pmd · GitHub

Affects PMD Version: 6.3.0 and before

Rule: ImmutableField

Description:
The ImmutableField rule can detect false positives when you have multiple constructors that call this() on each other.

Code Sample demonstrating the false positive:

public class AnalogAccelerometer {
  private AnalogInput m_analogChannel;
  private boolean m_allocatedChannel; // Violation

  public AnalogAccelerometer(final int channel) {
    this(new AnalogInput(channel));
    m_allocatedChannel = true;
  }

  public AnalogAccelerometer(final AnalogInput channel) {
    m_allocatedChannel = false;
    m_analogChannel = channel;
  }
}

Code Sample demonstrating the issue if I listened to PMD's recommendation:

public class AnalogAccelerometer {
  private AnalogInput m_analogChannel;
  private final boolean m_allocatedChannel;

  public AnalogAccelerometer(final int channel) {
    this(new AnalogInput(channel));
    m_allocatedChannel = true; // error: variable m_allocatedChannel might already have been assigned
  }

  public AnalogAccelerometer(final AnalogInput channel) {
    m_allocatedChannel = false;
    m_analogChannel = channel;
  }
}

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