Skip to content

Commit 95d5cca

Browse files
committed
fix: use declared erasure for type variables and wildcards
Pass-through rules like `java.util.List#get` returning `java.lang.Object` were no longer matching since typed method resolution via `cp.typeOf(method.enclosingClass)` surfaces declared return/parameter types as `JIRTypeVariable` (e.g. `E`) rather than the erased class. `erasedName()` fell through to `typeName`, producing the type-variable symbol `"E"` instead of `"java.lang.Object"`, so every string-based matcher missed. Map type variables and unbound wildcards to their declared erasure via `jIRClass.name`, and extend the same lookup to array element types.
1 parent bf8e6e4 commit 95d5cca

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

  • core/opentaint-configuration-rules/configuration-rules-jvm/src/main/kotlin/org/opentaint/dataflow/configuration/jvm

core/opentaint-configuration-rules/configuration-rules-jvm/src/main/kotlin/org/opentaint/dataflow/configuration/jvm/SerializedTypeMatching.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,24 @@ fun SerializedTypeNameMatcher.matchType(
5151

5252
/**
5353
* Erased class name for matching — drops any generic decoration that
54-
* [JIRType.typeName] may carry (e.g. `Map<String, Object>` → `java.util.Map`).
54+
* [JIRType.typeName] may carry (e.g. `Map<String, Object>` → `java.util.Map`)
55+
* and reduces a type variable / unbound wildcard to its declared erasure
56+
* (e.g. `E` → `java.lang.Object`) so string-based matchers can match against
57+
* pass-through rules whose return/parameter types show up as type variables
58+
* when resolved via the declaring class (e.g. `List.get` returns `E`).
5559
*/
5660
private fun JIRType.erasedName(): String = when (this) {
5761
is JIRClassType -> jIRClass.name
62+
is JIRTypeVariable -> jIRClass.name
63+
is JIRUnboundWildcard -> jIRClass.name
5864
is JIRArrayType -> {
5965
val el = elementType
60-
if (el is JIRClassType) el.jIRClass.name + "[]" else typeName
66+
when (el) {
67+
is JIRClassType -> el.jIRClass.name + "[]"
68+
is JIRTypeVariable -> el.jIRClass.name + "[]"
69+
is JIRUnboundWildcard -> el.jIRClass.name + "[]"
70+
else -> typeName
71+
}
6172
}
6273
else -> typeName
6374
}

0 commit comments

Comments
 (0)