INRIA / INRIA/spoon

[Bug]: spoon.support.reflect.declaration.CtTypeImpl.hasSameParameters(...) lacks an if condition

Open
#6,072 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

### Describe the bug

`spoon.support.reflect.declaration.CtTypeImpl.hasSameParameters(CtExecutable candidate, CtTypeReference... parameterTypes)` lacks an if condition without which a comparison between a non-array type parameter and a candidate executable with an array parameter can take place, leading to a wrong return value.

### Source code you are trying to analyze/transform

_No response_

### Source code for your Spoon processing

```Java
protected boolean hasSameParameters(CtExecutable candidate, CtTypeReference... parameterTypes) {
if (candidate.getParameters().size() != parameterTypes.length) {
return false;
}
for (int i = 0; (i < candidate.getParameters().size()) && (i < parameterTypes.length); i++) {
final CtTypeReference ctParameterType = candidate.getParameters().get(i).getType();
final CtTypeReference parameterType = parameterTypes[i];
if (parameterType instanceof CtArrayTypeReference) {
if (ctParameterType instanceof CtArrayTypeReference) {
if (!isSameParameter(candidate, ((CtArrayTypeReference) ctParameterType).getComponentType(), ((CtArrayTypeReference) parameterType).getComponentType())) {
return false;
} else {
if (((CtArrayTypeReference) ctParameterType).getDimensionCount() != ((CtArrayTypeReference) parameterType).getDimensionCount()) {
return false;
}
}
} else {
return false;
}
<-- Condition is lacking here, if ctParameterType is an Array Type Ref.
} else if (!isSameParameter(candidate, ctParameterType, parameterType)) {
return false;
}
}
return true;
}
```

### Actual output

_No response_

### Expected output

```Java
protected boolean hasSameParameters(
CtExecutable candidate, CtTypeReference... parameterTypes) {
if (candidate.getParameters().size() != parameterTypes.length) {
return false;
}
for (int i = 0; (i < candidate.getParameters().size()) && (i < parameterTypes.length);
i++) {
final CtTypeReference ctParameterType =
candidate.getParameters().get(i).getType();
final CtTypeReference parameterType = parameterTypes[i];
if (parameterType instanceof CtArrayTypeReference) {
if (ctParameterType instanceof CtArrayTypeReference) {
if (!isSameParameter(candidate,
((CtArrayTypeReference) ctParameterType).getComponentType(),
((CtArrayTypeReference) parameterType).getComponentType())) {
return false;
} else {
if (((CtArrayTypeReference) ctParameterType).getDimensionCount()
!= ((CtArrayTypeReference) parameterType).getDimensionCount()) {
return false;
}
}
} else {
return false;
}
//The following else if condition must be appended to fix the logic
} else if (ctParameterType instanceof CtArrayTypeReference) {
return false;
} else if (!isSameParameter(candidate, ctParameterType, parameterType)) {
return false;
}
}
return true;
}
```

### Spoon Version

11.0.1

### JVM Version

Not a JVM version issue

### What operating system are you using?

NixOS Vicuna, but not relevant for this bug

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.