You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
protectedbooleanhasSameParameters(CtExecutable<?> candidate, CtTypeReference<?>... parameterTypes) {
if (candidate.getParameters().size() != parameterTypes.length) {
returnfalse;
}
for (inti = 0; (i < candidate.getParameters().size()) && (i < parameterTypes.length); i++) {
finalCtTypeReference<?> ctParameterType = candidate.getParameters().get(i).getType();
finalCtTypeReference<?> parameterType = parameterTypes[i];
if (parameterTypeinstanceofCtArrayTypeReference) {
if (ctParameterTypeinstanceofCtArrayTypeReference) {
if (!isSameParameter(candidate, ((CtArrayTypeReference) ctParameterType).getComponentType(), ((CtArrayTypeReference) parameterType).getComponentType())) {
returnfalse;
} else {
if (((CtArrayTypeReference) ctParameterType).getDimensionCount() != ((CtArrayTypeReference) parameterType).getDimensionCount()) {
returnfalse;
}
}
} else {
returnfalse;
}
<-- Conditionislackinghere, ifctParameterTypeisanArrayTypeRef.
} elseif (!isSameParameter(candidate, ctParameterType, parameterType)) {
returnfalse;
}
}
returntrue;
}
Actual output
No response
Expected output
protectedbooleanhasSameParameters(
CtExecutable<?> candidate, CtTypeReference<?>... parameterTypes) {
if (candidate.getParameters().size() != parameterTypes.length) {
returnfalse;
}
for (inti = 0; (i < candidate.getParameters().size()) && (i < parameterTypes.length);
i++) {
finalCtTypeReference<?> ctParameterType =
candidate.getParameters().get(i).getType();
finalCtTypeReference<?> parameterType = parameterTypes[i];
if (parameterTypeinstanceofCtArrayTypeReference) {
if (ctParameterTypeinstanceofCtArrayTypeReference) {
if (!isSameParameter(candidate,
((CtArrayTypeReference) ctParameterType).getComponentType(),
((CtArrayTypeReference) parameterType).getComponentType())) {
returnfalse;
} else {
if (((CtArrayTypeReference) ctParameterType).getDimensionCount()
!= ((CtArrayTypeReference) parameterType).getDimensionCount()) {
returnfalse;
}
}
} else {
returnfalse;
}
//The following else if condition must be appended to fix the logic
} elseif (ctParameterTypeinstanceofCtArrayTypeReference) {
returnfalse;
} elseif (!isSameParameter(candidate, ctParameterType, parameterType)) {
returnfalse;
}
}
returntrue;
}
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
The text was updated successfully, but these errors were encountered:
I don't understand the problem. If you pass in a non-array parameter the type erasure will differ (Foo[] vs Foo) and the isSame check will fail. Can you provide a failing example? i.e. some source code using spoon where this produces wrong results?
You are correct, my unit tests were partially flawed. It is not a bug, however could be seen as an optimization. With proper tests isSameParameter() does distinguish between array and non-array, however this still may be an interesting change in that this will save unneeded typeErasure(...), qualified name generation and String compare operations. How should i proceed in this case?
Is this actually relevant in any program you found? If not, I would likely only make that change if it improves code clarity or does not impact it at all. It is not really worth it to trade complexity for performance without knowing whether it matters.
If I parse your diff correctly, the change is probably small enough that it could be okay, if you add an explanatory comment.
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
Actual output
No response
Expected output
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
The text was updated successfully, but these errors were encountered: