Skip to content

[java] matchesSig does not match some signatures that it should #6113

Closed

Description

@rdicroce

Affects PMD Version:

7.17.0

Description:

The matchesSig function for XPath rules doesn't match some methods.

Exception Stacktrace:

None

Code Sample demonstrating the issue:

package com.foo.bar;

import org.apache.logging.log4j.LogManager;

public class Test {
	
	public static void main(String[] args) {
		LogManager.getLogger();
	}
	
}

Steps to reproduce:

Given the above class, this XPath expression should match the method call:

//MethodCall[pmd-java:matchesSig('org.apache.logging.log4j.LogManager#getLogger()')]

But it doesn't. This (seemingly equivalent) XPath expression works fine:

//MethodCall[@MethodName='getLogger' and //ClassType[pmd-java:typeIs('org.apache.logging.log4j.LogManager')] and //ArgumentList[@Size=0]]

Running PMD through:

Designer

Activity

  1. added
    a:bug
    on Oct 2, 2025
  2. zbynek commented on Oct 4, 2025

    @zbynek
    Contributor

    matches-sig in general needs the source code or bytecode of the referenced class to be able to resolve overloads. In designer you can go to View > Analysis Classpath and add the .jar downloaded from https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api/2.25.2 , then the example above works.

    Maybe Designer could warn about missing classes in resolution though? Also this specific case when argument list is empty and class name is an exact match might be possible to handle without having the bytecode.

  3. rdicroce commented on Oct 6, 2025

    @rdicroce
    Author

    Ah, that makes sense. I agree that the designer should warn about missing classes.

    I think there's also an unrelated bug with setting the analysis classpath. When I added the JAR, that didn't seem to have any effect until I changed the source level from 25 to something else. It still worked fine after changing it back, so I'm guessing something isn't reloading the classpath when items are added/removed.

  4. zbynek commented on Oct 15, 2025

    @zbynek
    Contributor

    I suggest to close this in favor of pmd/pmd-designer#258 and pmd/pmd-designer#257 (feel free to reopen if you think something needs changing in this repo).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions