GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] Fix #7216: GuardLogStatement: accept logstash structured arguments by princejain756 · Pull Request #7225 · pmd/pmd

Conversation

@princejain756

@princejain756 princejain756 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Describe the PR

log.debug("user={}", value("user", user)) was flagged by GuardLogStatement although the logstash StructuredArguments helpers only wrap the argument for the structured encoder; the string rendering stays deferred exactly like plain {} parameter substitution, so a level guard buys nothing.

The rule now treats any argument of type net.logstash.logback.argument.StructuredArgument as low overhead, which covers value, keyValue, entries, defer and user factories returning the same type. Arbitrary method calls are still flagged.

A test-scoped logstash-logback-encoder dependency was added so the regression test can resolve the argument type, matching the existing typeresolution test deps.

Related issues

  • Fixes [java] GuardLogStatement: False positive on SLF4J parameterised calls whose arguments are wrapped with logstash value(...) #7216

Ready?

  • Added unit tests for fixed bug/feature (GuardLogStatement XML: value/keyValue/entries unflagged, a plain helper call still flagged)
  • Passing all unit tests (46/46 GuardLogStatementTest, red-verified without the rule change: 4 violations instead of 1)
  • Complete build using ./mvnw verify at the project root (module compile, test, checkstyle and pmd:check run locally for pmd-java)
  • A changelog entry under java-bestpractices
  • Commit message explains the why

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
zbynek
zbynek requested changes Oct 23, 2026
View reviewed changes

@zbynek zbynek left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me how pedantic this rule should be -- calling a constructor for even a lightweight object still creates overhead.

Assuming we're okay with that constructor call (as the linked issue suggests), the rule should still not allow value("user", slowMethodToGetUser()) as an argument.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@princejain756

princejain756 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Good catch @zbynek. Updated isStructuredLoggingArgument so that when a StructuredArgument is produced by a method or constructor call (InvocationNode), all arguments passed into that call must also pass isLowOverheadParam (plus a test case for value("user", computeName(user))).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

zbynek
zbynek approved these changes Oct 23, 2026
View reviewed changes

@zbynek zbynek left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic looks good now, thanks. Please resolve the release notes merge conflict.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@princejain756

princejain756 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Resolved the release notes conflict against main.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pmd-actions-helper

pmd-actions-helper Bot commented Oct 25, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 16 errors and 9 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-11-08 20:35:49+00:00 for c20c126)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@princejain756
princejain756 force-pushed the fix-guard-log-statement-structured-args branch 2 times, most recently from 2fc01cb to cf5e380 Compare November 5, 2026 23:44
@zbynek
zbynek requested a review from adangel November 5, 2026 23:57
princejain756 added 2 commits November 8, 2026 22:56
@princejain756
[java] GuardLogStatement: accept logstash structured arguments (pmd#7216
95ea7d2
)

log.debug("user={}", value("user", user)) was flagged although its
argument cost is the same as plain parameter substitution: the logstash
helper call returns a StructuredArgument whose string rendering is
deferred to the encoder.

Treat arguments of type net.logstash.logback.argument.StructuredArgument
as low overhead, covering value, keyValue, entries and user helpers
returning the same type. Arbitrary method calls still require a guard.

Adds logstash-logback-encoder as a test-scoped dependency so the
regression test resolves the argument type.
@princejain756
[java] GuardLogStatement: check arguments passed into StructuredArgum…
39f72b0
…ent calls
@princejain756
princejain756 force-pushed the fix-guard-log-statement-structured-args branch from cf5e380 to 39f72b0 Compare November 8, 2026 17:27
UncleOwen added 4 commits November 8, 2026 20:47
@UncleOwen
Fix broken merge
2734a2f
@UncleOwen
Merge branch 'main' into fork/princejain756/fix-guard-log-statement-s…
ad2b0ea
…tructured-args
@UncleOwen
Keep issue title intact
d54d06c
@UncleOwen
Move new code so that calls go from top to bottom
c20c126
(excluding indirect recursion)
@UncleOwen UncleOwen added this to the 7.30.0 milestone Nov 8, 2026
UncleOwen
UncleOwen approved these changes Nov 8, 2026
View reviewed changes

@UncleOwen UncleOwen left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@UncleOwen
UncleOwen merged commit 63850a0 into pmd:main Nov 8, 2026
13 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel changed the title [java] GuardLogStatement: accept logstash structured arguments [java] Fix #7216: GuardLogStatement: accept logstash structured arguments Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@zbynek zbynek zbynek approved these changes
@UncleOwen UncleOwen UncleOwen approved these changes
@adangel adangel Awaiting requested review from adangel

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

7.30.0

Development

Successfully merging this pull request may close these issues.

[java] GuardLogStatement: False positive on SLF4J parameterised calls whose arguments are wrapped with logstash value(...)

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@princejain756 @zbynek @UncleOwen
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.