1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
// Tests string length refinement after startsWith or endsWith return true
// https://github.com/kelloggm/checker-framework/issues/56
import org.checkerframework.common.value.qual.ArrayLen;
import org.checkerframework.common.value.qual.MinLen;
class StartsEndsWith {
void refineStartsWith(String str) {
if (str.startsWith("prefix")) {
@MinLen(6) String s6 = str;
// :: error: (assignment.type.incompatible)
@MinLen(7) String s7 = str;
} else {
// :: error: (assignment.type.incompatible)
@MinLen(6) String s6 = str;
}
}
void refineEndsWith(String str) {
if (str.endsWith("suffix")) {
@MinLen(6) String s6 = str;
// :: error: (assignment.type.incompatible)
@MinLen(7) String s7 = str;
} else {
// :: error: (assignment.type.incompatible)
@MinLen(6) String s6 = str;
}
}
void refineStartsEndsWith(String str) {
if (str.startsWith("longprefix") && str.endsWith("prefix")) {
@MinLen(10) String s10 = str;
// :: error: (assignment.type.incompatible)
@MinLen(11) String s11 = str;
}
}
void refineStartsArrayLen(String str, @ArrayLen(10) String prefix) {
if (str.startsWith(prefix)) {
@MinLen(10) String sg10 = str;
// :: error: (assignment.type.incompatible)
@ArrayLen(10) String s10 = str;
}
}
void noRefinement(@ArrayLen(10) String str) {
if (str.startsWith("x")) {
@ArrayLen(10) String s10 = str;
}
}
void refineStartsStaticFinal(String str) {
if (str.startsWith(StartsEndsWithExternal.staticFinalField)) {
@MinLen(3) String s3 = str;
}
}
}
class StartsEndsWithExternal {
public static final String staticFinalField = "str";
}
|