-
Notifications
You must be signed in to change notification settings - Fork 371
Open
Labels
bugSomething isn't workingSomething isn't working
Description
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.methodFullNameshould be updated to the actual method's full namecall.signatureshould be updated tovoid(com.example.Animal)
Actual CPG result:
- The call remains unmatched
call.methodFullNamestays as<unresolvedNamespace>.process:<unresolvedSignature>(1)call.signatureremains<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:
- The type matching should consider the class hierarchy (inheritance relationships)
- If argument type A is a subclass of parameter type B, they should be considered compatible
- 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
warama17
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working