Skip to content

[java] PrematureDeclaration as result of method call (false positive) #1429

@ben-manes

Description

@ben-manes

Affects PMD Version:
6.9.0

Rule:
PrematureDeclaration

Description:
The result of a ConcurrentMap#put is captured for handling later in the method. As put has a side effect, the logic changes if the declaration is moved downward.

Code Sample demonstrating the issue:

var prior = cache.put(uri, cachedPath);

if (ref == null) {
  return PathRef.create(cachedPath, 1);
}
if (prior == null) {
  ref.count().incrementAndGet();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions