You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The rule UseObjectForClearerAPI reports methods that take more than 3 String parameters. I think the justification is ok, but it's bizarre to single out strings. OTOH, generalizing this to any type of argument just gives ExcessiveParameterList. Although it's less thoroughly justified, ExcessiveParameterList also recommends using an object to wrap parameters.
Another problem with UseObjectForClearerAPI is that it doesn't care about constructors. Clearly,
callFun("a", "b", "c", "d")
is no less readable than
callFun(newFunArguments("a", "b", "c", "d"))
So to stay true to its goal of increasing readability, the rule should flag constructors, and also not simply recommend using an object, but also maybe the builder pattern. Since this is burned into the rule name we can't really change that (the rule name doesn't match our guidelines).
I think UseObjectForClearerAPI should be deprecated and its description used to enrich the description of ExcessiveParameterList.
+1 This rule also doesn't seem to account for overriding of library / JDK methods. For example, rule is violated by overriding org.xml.sax.ext.DefaultHandler2#resolveEntity(java.lang.String, java.lang.String, java.lang.String, java.lang.String) when implementing a custom handler.
I think it did make sense to single out strings – one may be tempted to use strings for everything (especially if the data comes from an untyped source like a properties file or a servlet request), which highly increases the risk of swapping parameters without causing compile-time errors. Consider the following signature:
voidbanUser(Stringuuid, Stringduration, Stringreason, Stringnotify);
banUser("00000000-0000-0000-0000-000000000000", "bad behavior", "1 day", "true"); // Whoops, duration and reason swapped, but the compiler doesn’t notice this
with the following one:
voidbanUser(java.util.UUIDuuid, java.time.Durationduration, Stringreason, booleannotify);
banUser(newUUID(0, 0), "bad behavior", Duration.ofDays(1), true); // Compilation failure due to the signature mismatch
Four parameters are not that excessive that I’d want to configure ExcessiveParameterList to report that regardless of the type, but four strings in a row are confusing and should be avoided if possible.
Activity
zman0900 commentedon Apr 24, 2025
+1 This rule also doesn't seem to account for overriding of library / JDK methods. For example, rule is violated by overriding
org.xml.sax.ext.DefaultHandler2#resolveEntity(java.lang.String, java.lang.String, java.lang.String, java.lang.String)when implementing a custom handler.[doc] Update release notes (#3741, #6779)
[java] Fix pmd#3741: Deprecate UseObjectForClearerApi (pmd#6779)
jtotht commentedon Jul 7, 2026
I just noticed this in the release notes.
I think it did make sense to single out strings – one may be tempted to use strings for everything (especially if the data comes from an untyped source like a properties file or a servlet request), which highly increases the risk of swapping parameters without causing compile-time errors. Consider the following signature:
with the following one:
Four parameters are not that excessive that I’d want to configure
ExcessiveParameterListto report that regardless of the type, but four strings in a row are confusing and should be avoided if possible.