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
Consider the below test case.
Without the @AssumeAssertion, the Index Checker issues the warning.
MethodComparator.java:23: error: [array.access.unsafe.high] Potentially unsafe array access: the index could be larger than the array's bound
result = ptypes1[i].toString().compareTo(ptypes2[i].toString());
^
found : @LTLengthOf(value="ptypes1", offset="0") int
required: @IndexFor("ptypes2") or @LTLengthOf("ptypes2") -- an integer less than ptypes2's length
1 error
I think that comparing the subtraction (difference) of array lengths is somewhat common in compare and compareTo methods.
importjava.lang.reflect.Method;
importjava.util.Comparator;
publicclassMethodComparatorimplementsComparator<Method> {
@Overridepublicintcompare(Methodm1, Methodm2) {
Class<?>[] ptypes1 = m1.getParameterTypes();
Class<?>[] ptypes2 = m2.getParameterTypes();
intresult;
result = ptypes1.length - ptypes2.length;
if (result != 0) {
returnresult;
}
assertptypes1.length == ptypes2.length : "@AssumeAssertion(index): difference of lengths is 0";
for (inti = 0; i < ptypes1.length; i++) {
result = ptypes1[i].toString().compareTo(ptypes2[i].toString());
if (result != 0) {
returnresult;
}
}
returnresult;
}
}
The text was updated successfully, but these errors were encountered:
Consider the below test case.
Without the
@AssumeAssertion
, the Index Checker issues the warning.I think that comparing the subtraction (difference) of array lengths is somewhat common in
compare
andcompareTo
methods.The text was updated successfully, but these errors were encountered: