GeezerVison is showing github.com — [java] Deprecate getImage()/@Image and remove usages by UncleOwen · Pull Request #7048 · pmd/pmd
Conversation
UncleOwen
commented
Sep 7, 2026
•
edited by adangel
Loading
Uh oh!
There was an error while loading. Please reload this page.
Part of #4787
Describe the PR
This PR removes the remaining uses of @Image/Node.getImage() from pmd-java.
Related issues
Ready?
- Added unit tests for fixed bug/feature
- Passing all unit tests
- Complete build
./mvnw clean verify passes (checked automatically by github actions)
- Added (in-code) documentation (if needed)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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, 0 errors and 0 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-10-22 14:34:40+00:00 for 2dd4db6)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
UncleOwen
changed the title
[java] Work on #4787 remove remaining usages of @Image/Node.getImage()
[java] Work on #4787: remove remaining usages of @Image/Node.getImage()
Sep 7, 2026
…of-getImage
# Conflicts:
# pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/FieldNamingConventionsRule.java
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 for the PR!
I'd prefer, if we directly prepare the deprecation of getImage here. That means
- we don't use the parsers setLastTokenImage anymore (which would call setImage on the node)
- we have for all these cases in the node a proper alternative attribute and getImage returns that attribute. The parser will call the set_name_of_the_attribute setter instead of setLastTokenImage
I've tested this approach with ASTBreakStatement - there are no test failures, so I assume, we don't use break statements with labels in any sample file we have a treedump test... which means, in that case, we can directly deprecated it (note: release notes).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…of-getImage
# Conflicts:
# pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/SuspiciousOctalEscapeRule.java
UncleOwen
commented
Oct 19, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
When I wrote this PR, I didn't want to touch the parser. That's why we wouldn't be able to deprecate setImage(). But I think this PR does enable us to deprecate getImage() and the image variable. At least, as far as Java is concerned. Looking back at it, I agree that this asymmetry is confusing. Should I continue working on this PR, so we can deprecate setImage() as well?
As for making sure that getImage() still works even if deprecated: We could add an assert getImage().equals(getLabel()) in ASTBreakStatement.jjtClose().
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Hmmm, maybe jjtClose is too early.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
adangel
changed the title
[java] Work on #4787: remove remaining usages of @Image/Node.getImage()
[java] Deprecate getImage()/@Image and remove usages
Oct 22, 2026
adangel
commented
Oct 22, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Hmmm, maybe jjtClose is too early.
I've continued and finished this PR. I've decided to not use assert in jjtClose and just have unit tests, to verify image attribute.
Note: This is only a first step towards #4787 . I've outlined there the next steps for java:
- Deprecate @Image of: ASTCompactConstructorDeclaration, ASTEnumConstant, ASTInfixExpression, ASTStringLiteral (and all other subtypes of AbstractLiteral - last usage of setImage)
- Deprecate @Image of remaining nodes (inherited through AbstractJjtreeNode). Deprecation in AbstractJavaNode. In theory, this should not affect any more nodes, because setImage is not used anymore.
If the build looks fine, I'm going to merge this for 7.29.0.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
adangel
adangel left review comments
Uh oh!
There was an error while loading. Please reload this page.
Labels
is:deprecation
The main focus is deprecating public APIs or rules, eg to make them internal, or removing them
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|