Skip to content

[java] GuardLogStatement: False positive with compile-time constant arguments #957

@Myllyenko

Description

@Myllyenko

Affects PMD Version: 6.1.0 (and other ones I think)

Rule: GuardLogStatement

Description: As stated in the rule's description, the rule is intended for helping programmers to 'skip the associate String creation and manipulation' but currently it triggers at any String + String-like construct even if the resulting value is actually a literal and no Object creation is involved at all.

Code Sample demonstrating the issue:

First, the sample from the rule's description:

log.debug("log something" + " and " + "concat strings"); // the same as "log something and concat strings"

Second, more advanced case:

final String constantPrefix = "log something";
final String constantSuffix = "concat strings";
log.debug(constantPrefix + " and " + constantSuffix ); // the same as "log something and concat strings"

Running PMD through: Doesn't matter

Metadata

Metadata

Assignees

Labels

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

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions