Skip to content

[java] GuardLogStatement: Documentation is unclear why getters are flagged #4731

@soloturn

Description

@soloturn

Affects PMD Version:
7.0.0-rc4

Rule:
GuardLogStatement: Logger calls should be surrounded by log level guards.

Description:

            if (handler.isPresent()) {
                handlerMap.put(field, handler.get());
            } else {
                logger.error("Unsupported field: '{}.{}'", type.getId(), field.getName());
            }
        }

other example:

            if (result == null) {
                logger.warn("Unknown enum value: '{}' for enum {}", data.getAsString(), enumType.getSimpleName());
            }

Expected outcome:

PMD reports a violation at line "logger.error", the example in the documentation says: no guard necessary if parameters are there; getters are parameters.

Running PMD through: Gradle

Metadata

Metadata

Assignees

No one assigned

    Labels

    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