Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump PMD to version 7.0.0 #17717

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Bump PMD to version 7.0.0 #17717

wants to merge 12 commits into from

Conversation

crammond
Copy link

I've been playing around with upgrading RuneLite to Java 21. Part of that work would require upgrading PMD to version 7.0.0, which was a big enough change on its own that felt like it needed its own PR.

@Adam-
Copy link
Member

Adam- commented Apr 11, 2024

I've looked into this before, but decided to not update because they made the immutable field check no longer work with Lombok (I guess due to the new Java record types?). But since we use Lombok so heavily it is just a loss of functionality. I'd probably rather just remove the immutable field check than go around and annotate everything as PMD ignore though.

I am not familiar with this pmd-compat6 dep, do you know what that is for?

@crammond
Copy link
Author

crammond commented Apr 11, 2024

I've looked into this before, but decided to not update because they made the immutable field check no longer work with Lombok (I guess due to the new Java record types?). But since we use Lombok so heavily it is just a loss of functionality. I'd probably rather just remove the immutable field check than go around and annotate everything as PMD ignore though.

PMD's states their reasoning here. It's an unfortunate change considering use cases like Lombok. I'd be happy to modify this PR to remove that rule if there is still interest in the upgrade, though.

I am not familiar with this pmd-compat6 dep, do you know what that is for?

This was added specifically to support maven-pmd-plugin until they update to version 7.0.0 themselves (relevant release notes). There's already a PR to do that here, apache/maven-pmd-plugin#144, so the need for pmd-compat6 will go away quickly.

@Adam-
Copy link
Member

Adam- commented Apr 11, 2024

I guess I don't mind the update / I am sort of indifferent to it. I see you mentioned moving to Java 21, but to do that we first have to update the launcher to 21 and then push launcher updates out. Updating the launcher version is a pretty major thing, is somewhat irreversible, and tends to uncover obscure Java bugs and also break our code in places we are depend on 11 specific functionality. It is not something I want to sink a bunch of time in unless I have a compelling reason to update.

@Adam-
Copy link
Member

Adam- commented Apr 11, 2024

pmd/pmd#4474 looks like they made it ignore fields annotated with @Getter or @Setter in 7.0.0. Do you know why you are still having to annotate those fields as ignored?

@crammond
Copy link
Author

I see you mentioned moving to Java 21, but to do that we first have to update the launcher to 21 and then push launcher updates out. Updating the launcher version is a pretty major thing, is somewhat irreversible, and tends to uncover obscure Java bugs and also break our code in places we are depend on 11 specific functionality. It is not something I want to sink a bunch of time in unless I have a compelling reason to update.

Thanks for your thoughts on this. I mentioned it in this PR to gauge interest, and it is understandable that you would not want to push for the upgrade without a very good reason, which I admittedly do not have. I also see in the launcher that you are currently depending on JDKs with 32bit Windows support for which there does not seem to be a temurin offering at this time.

they made it ignore fields annotated with @Getter or @Setter in 7.0.0. Do you know why you are still having to annotate those fields as ignored?

Ah, great catch. I was following their migration guide which suggested going to 6.55.0 first before 7.0.0, and I think as a result 6.55.0 reported these erroneously and I fixed them before bumping to 7.0.0. Let me redo the version bump in one go and see what changes that ends up requiring.

@crammond
Copy link
Author

I believe that is 27 less use cases of @SuppressWarnings("PMD.ImmutableField") than I had before, great catch!

Copy link
Member

@Adam- Adam- left a comment

Choose a reason for hiding this comment

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

There are also several // NOPMD in the code, some of them can be removed because they have been fixed upstream I think. Please check those.

@@ -56,7 +56,7 @@ private static final class Entry
private String title;

@Getter
private List<Entry> options = new ArrayList<>();
private final List<Entry> options = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

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

are all of these types of changes (setting final on getter/setter fields) then also unnecessary? Ideally I'd like the minimum amount of change that keeps pmd happy.

Copy link
Author

Choose a reason for hiding this comment

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

I believe PMD is intentionally still flagging @Getter only fields. I did a re-run from master with 7.0.0 and these are the changes it asked for.

Copy link
Member

Choose a reason for hiding this comment

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

Is the ImmutableFieldRule flagging it? Since it really looks like it shouldn't pmd/pmd@66ddd56#diff-f0d84f4b43ab1c1e2fbc8b8ee09c4c0c3ee2c5a7b981d99fae749652821ec07aR64

Copy link
Author

Choose a reason for hiding this comment

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

It is, @Getter was specifically removed a few days later per pmd/pmd@d9a98b9

</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-javascript</artifactId>
Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Author

Choose a reason for hiding this comment

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

I meant to comment or add more info in the commit message, but maven-pmd-plugin depends on these, and I think with the API changes from 6 to 7 pmd-compat6 needs all of these updated and available to work properly. Their docs for upgrading PMD at runtime also show upgrading these packages too.

</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-jsp</artifactId>
Copy link
Member

Choose a reason for hiding this comment

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

?

@crammond crammond force-pushed the pmd-7 branch 2 times, most recently from 6cd9ed8 to 530b436 Compare April 18, 2024 01:23
@crammond
Copy link
Author

There are also several // NOPMD in the code, some of them can be removed because they have been fixed upstream I think. Please check those.

I was able to remove a couple of // NOPMDs in the code without changes. I also checked old @SuppressWarnings("PMD.<Rule>")s but they were still needed without other changes.

@@ -1879,6 +1879,7 @@ public int[] getConfigKeys()
return new int[]{text.hashCode()};
}

@SuppressWarnings("PMD.UnusedPrivateMethod")
Copy link
Author

Choose a reason for hiding this comment

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

Possibly pmd/pmd#4861

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants