Modify ↓

Opened 8 months ago

Last modified 2 days ago

#24635 new task

Fix new PMD warnings

Reported by: stoecker Owned by: team
Priority: normal Milestone: 26.09
Component: Core Version:
Keywords: Cc: gaben, GerdP

Description

After PMD upgrade a bunch of new warnings cam up.

Anyone time to help fixing them?

Attachments (1)

josm_24635.patch​ (58.9 KB ) - added by gaben 3 weeks ago.

Download all attachments as: .zip

Change History (41)

comment:1 by gaben, 8 months ago

Anyone time..?

I don't have any at the moment, but hopefully I will have some in the following weeks.

comment:2 by GerdP, 8 months ago

Sorry, the recent changes caused another build failure in my Eclipse installation, so atm I try to fix that.

comment:3 by stoecker, 8 months ago

I found that an "svn cleanup --remove-ignored" helped. I had to do this for the CI to work.

comment:4 by stoecker, 8 months ago

Also note, that while I tried to keep downwards compatibility intact I may have created some places where Java >= 21 is required. I don't plan to actively search such issues as long as the JOSM server stuff for the needed builds does still work with Java 11.

comment:5 by GerdP, 8 months ago

My problems with Eclipse are fixed. No idea what exactly was wrong, it used an older version of the compression library.

comment:6 by GerdP, 8 months ago

Where do I see the bunch of PMD warnings?

comment:7 by GerdP, 8 months ago

Ah, didn't use svn update today. Now I see when running ant pmd

in reply to:  5 comment:8 by stoecker, 8 months ago

Replying to GerdP:

My problems with Eclipse are fixed. No idea what exactly was wrong

That's the reason why I don't use eclipse. That "No idea why" happened too often to me...

comment:9 by GerdP, 8 months ago

I can take care about the "Public member ... declared in a non-public type" messages. My understanding is that I just have to remove the public key word.

in reply to:  9 comment:10 by stoecker, 8 months ago

Replying to GerdP:

I can take care about the "Public member ... declared in a non-public type" messages. My understanding is that I just have to remove the public key word.

Or change to "protected"? I'm not totally sure. Had only a short look at the PMD description.

comment:11 by GerdP, 8 months ago

In ​https://github.com/pmd/pmd/pull/6231 I see that either public should be removed or private should be added.
Anyhow there seem to be more to this because when I change the flagged places in src\org\openstreetmap\josm\data\coor\Coordinate.java I can no longer compile. Not yet sure if this is a PMD error or if I have to change more code.

comment:12 by stoecker, 8 months ago

In 19520/josm:

ignore rule PublicMemberInNonPublicType, see #24635

comment:13 by stoecker, 8 months ago

In 19535/josm:

remove a lot of PMD warnings, especially outdated ignores, see #24635

comment:14 by stoecker, 8 months ago

In 19536/josm:

remove PMD ImplicitFunctionalInterface, see #24635

comment:15 by stoecker, 8 months ago

In 19537/josm:

fix one more PMD, see #24635

comment:16 by stoecker, 8 months ago

In 19538/josm:

fix one more PMD, see #24635, drop java.util.Date in SyncEditorLayerIndex

comment:17 by stoecker, 8 months ago

Only 2 types missing:

  • ReplaceJavaUtilDate
  • OverrideBothEqualsAndHashCodeOnComparable

comment:18 by stoecker, 8 months ago

In 19539/josm:

see #24635 - remove usage of Date

comment:19 by stoecker, 7 months ago

In 19541/josm:

remove outdated expiry data check, see #24635

comment:20 by stoecker, 6 months ago

Milestone: 26.03 → 26.05

comment:21 by stoecker, 3 months ago

Milestone: 26.05 → 26.07

Milestone renamed

comment:22 by stoecker, 2 months ago

Milestone: 26.07 → 26.09

comment:23 by gaben, 3 weeks ago

Are core plugins in the scope?

by gaben, 3 weeks ago

Attachment: josm_24635.patch​ added

comment:24 by gaben, 3 weeks ago

So as you see I used PMD 7.27 (not updated in Ant and Ivy yet), but with the current 7.22 the config change not causing anything meaningful change, maybe one more false positive.

PMD config: I removed the obsolete excludes that are no longer in version 7.x. I also removed e.g. the InefficientEmptyStringCheck performance rule exclusion, since Java 11+ has the isBlank() method, and a few more, which do not report violations on the trunk version.

What remains that I don't like is the rule ExhaustiveSwitchHasDefault; it's a bit noisy in my opinion. There are also a few OverrideBothEqualsAndHashCodeOnComparable.

Last edited 3 weeks ago by gaben (previous) (diff)

comment:25 by stoecker, 2 weeks ago

What remains that I don't like

Disable it? :-)

comment:26 by gaben, 4 days ago

Will we have a release this month? If not, I would like to start applying the fixes for the warnings and update the config/upgrade PMD to latest version.

comment:27 by stoecker, 3 days ago

Actually I planned to have a release. But it seems I have no time. In any case don't delay any changes.

comment:28 by gaben, 3 days ago

In 19628/josm:

see #24635 - update PMD to 7.28.0 and re-enable several rules, remove deprecated and not reporting ones

comment:29 by gaben, 3 days ago

In 19629/josm:

see #24635 - fix PMD violations

  • use String.isBlank() instead of trim().isEmpty(),
  • method references,
  • EnumMap for enum keys
  • drop redundant initializers/toString() calls and unused annotations,
  • remove unused private getDefensiveDate()
  • use an explicit charset for Content-length

comment:30 by gaben, 3 days ago

In 19630/josm:

see #24635 - drop protected modifier on nested types of final classes

comment:31 by gaben, 3 days ago

In 19631/josm:

see #24635 - re-enable SimplifiedTernary rule and fix the warning

comment:32 by gaben, 3 days ago

In 19632/josm:

see #24635 - fix one more SimplifyConditional violation

comment:33 by stoecker, 2 days ago

In 19633/josm:

see #24635 - disable wrong warnings

comment:34 by gaben, 2 days ago

I don't see UnusedPrivateMethod on PMD 7.28.0. I updated it in r19628. Are you using this version?

In fact, there are two new UnnecessaryWarningSuppression.

comment:35 by stoecker, 2 days ago

In 19635/josm:

see #24635 - fix some PMD warnings

comment:37 by stoecker, 2 days ago

Well, It's running 7.28 as well...

But it seems the results differ.

comment:38 by stoecker, 2 days ago

Wonderful, another one in last change: GitHub PMD complains about "@SuppressWarnings" and "ant pmd" issues "CloseResource" for MapboxVectorCachedTileLoader.java

Can we get that unified?

comment:39 by stoecker, 2 days ago

In 19636/josm:

readd suppress, see #24635

comment:40 by gaben, 2 days ago

So ant pmd includes the script/ folder, while maven pmd:pmd does not. I used the latter one, CI uses ant pmd for the PMD action.

However, this still does not explain the issue. I also suspect that there are only 10 errors displayed on GitHub due to some kind of limitation.

Can we get that unified?

Sure. I'll look into that as well besides ticket:24234#comment:53, after I finished the Java 17 migration locally, if that's okay :) Already made changes in over 600 files summed and over 10 branches. Mostly mechanical replacements.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain team.
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from team to the specified user.
Next status will be 'needinfo'. The owner will be changed from team to stoecker.
as duplicate The resolution will be set to duplicate. Next status will be 'closed'. The specified ticket will be cross-referenced with this ticket.
The owner will be changed from team to anonymous. Next status will be 'assigned'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.