A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/590 below:

[java] False positive on MissingStaticMethodInNonInstantiatableClass · Issue #590 · pmd/pmd · GitHub

I've recently come across a bunch of false positives on this rule.

  1. When looking for builder patterns it looks for public constructors, but fails when using the default one. The culprit is the line:
[count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Public='true']) > 0]

which should be

[count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Public='true']) > 0 or not(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration)]
  1. As part of the builder pattern detection (which shouldn't be needed and we can possibly get rid of), we check for a method returning an object defined on this very file, but we don't check if it's a nested type or not (shouldn't), and we require the use of the this qualifier, which is too weak to be of any use:
 and
  count(//ClassOrInterfaceDeclaration
            [@Nested='true']
            [@Static='true']
            [@Public='true']
            [.//MethodDeclaration
              [@Public='true']
              [.//ReturnStatement//AllocationExpression
                [ClassOrInterfaceType
                    [@Image = //ClassOrInterfaceDeclaration/@Image]
                ]
                [./Arguments//PrimaryPrefix/@ThisModifier='true']
              ]
            ]
       ) = 0

We should probably drop this last check altogether, improve the static builder detection, add a proper test and make sure we didn't break anything.

I'm away of the PC right now, so I'm creating this issue to keep track of it. I'll fix it as soon as I can.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4