Skip to content

[Bug][javasrc2cpg]TypeInferencePass fails to match method calls when argument types are subclasses of declared parameter types #5679

Open

Description

@jjzdxmd

Bug Description

The TypeInferencePass fails to match method calls when the argument types are subclasses of the declared parameter types. The type matching logic in doArgumentTypesMatch() only performs exact type matching and does not consider inheritance hierarchies.
Root Cause: Java's Liskov Substitution Principle allows subclass instances to be passed where parent class instances are expected. The current implementation violates this by requiring exact type matches.

Reproduce

Test case:Method call with subclass argument

// Class hierarchy
class Animal { }
class Dog extends Animal { }

// Method declaration
public void process(Animal animal) { }

// Method call
Dog dog = new Dog();
process(dog);

Expected CPG result:

  • The call should be matched to the process(Animal) method
  • call.methodFullName should be updated to the actual method's full name
  • call.signature should be updated to void(com.example.Animal)

Actual CPG result:

  • The call remains unmatched
  • call.methodFullName stays as <unresolvedNamespace>.process:<unresolvedSignature>(1)
  • call.signature remains <unresolvedSignature>(1)

Debug output:

Checking method: com.example.MyClass.process:void(com.example.Animal)
  parameterSizesMatch: true (1 == 1)
  argTypesMatch: false
    [0] Param: animal (com.example.Animal) vs Arg: dog (com.example.Dog) -> Match: false
  hasDifferingArg: true
  RESULT: false

Expected behavior

The TypeInferencePass should correctly match method calls where argument types are subclasses of the declared parameter types. Specifically:

  1. The type matching should consider the class hierarchy (inheritance relationships)
  2. If argument type A is a subclass of parameter type B, they should be considered compatible
  3. Method calls with subclass arguments should be successfully resolved when a matching parent-class method exists

Desktop

OS: macOS
Joern Version: latest
Java version: 21

Activity

  1. changed the title [-][Bug]TypeInferencePass fails to match method calls when argument types are subclasses of declared parameter types[/-] [+][Bug][javasrc2cpg]TypeInferencePass fails to match method calls when argument types are subclasses of declared parameter types[/+] on Oct 15, 2025
  2. warama17 commented on Oct 17, 2025

    @warama17

    Hello!
    I encountered the same issue.
    I tried using the fetch-dependencies option when creating the CPG, but the result was the same.

    /opt/joern/joern-cli/javasrc2cpg -J-Xmx16016m --fetch-dependencies <input_path> --output <output_path>/cpg.bin.zip

    I would like to know how to resolve this, too.

  3. jjzdxmd commented on Oct 20, 2025

    @jjzdxmd
    ContributorAuthor

    Hello! I encountered the same issue. I tried using the fetch-dependencies option when creating the CPG, but the result was the same.

    /opt/joern/joern-cli/javasrc2cpg -J-Xmx16016m --fetch-dependencies <input_path> --output <output_path>/cpg.bin.zip

    I would like to know how to resolve this, too.

    I tried to modify the doArgumentTypesMatch() and add some type matching logic like "|| is subtype of" then recompile javasrc2cpg. but i wanna them give a solution too

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions