Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ protected void commonAssignmentCheck(
}

@Override
protected boolean isTypeCastSafe(AnnotatedTypeMirror castType, AnnotatedTypeMirror exprType) {
protected CastSafeKind isTypeCastSafe(
AnnotatedTypeMirror castType, AnnotatedTypeMirror exprType) {

AnnotationMirror exprLTAnno =
exprType.getEffectiveAnnotationInHierarchy(atypeFactory.LESS_THAN_UNKNOWN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -977,9 +977,10 @@ DeclaredType typeToCheck() {
}

@Override
protected boolean isTypeCastSafe(AnnotatedTypeMirror castType, AnnotatedTypeMirror exprType) {
protected CastSafeKind isTypeCastSafe(
AnnotatedTypeMirror castType, AnnotatedTypeMirror exprType) {
if (castType.getKind().isPrimitive()) {
return true;
return CastSafeKind.SAFE;
}
return super.isTypeCastSafe(castType, exprType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,10 @@ private boolean noMustCallObligation(AnnotatedTypeMirror atm) {
}

@Override
protected boolean isTypeCastSafe(AnnotatedTypeMirror castType, AnnotatedTypeMirror exprType) {
protected CastSafeKind isTypeCastSafe(
AnnotatedTypeMirror castType, AnnotatedTypeMirror exprType) {
if (noMustCallObligation(castType) || noMustCallObligation(exprType)) {
return true;
return CastSafeKind.SAFE;
}

return super.isTypeCastSafe(castType, exprType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,11 @@ public Void visitCompoundAssignment(CompoundAssignmentTree node, Void p) {
}

@Override
protected boolean isTypeCastSafe(AnnotatedTypeMirror castType, AnnotatedTypeMirror exprType) {
protected CastSafeKind isTypeCastSafe(
AnnotatedTypeMirror castType, AnnotatedTypeMirror exprType) {
if (!atypeFactory.maybeIntegral(castType)) {
// If the cast is not a number or a char, then it is legal.
return true;
return CastSafeKind.SAFE;
}
return super.isTypeCastSafe(castType, exprType);
}
Expand Down
4 changes: 2 additions & 2 deletions checker/tests/lock/ChapterExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void someMethod() {
o2 = o1; // {"lock"} and {} are not identical sets.
}

@SuppressWarnings("lock:cast.unsafe")
@SuppressWarnings("lock:cast.incompatible")
void someMethod2() {
// A cast can be used if the user knows it is safe to do so.
// However, the @SuppressWarnings must be added.
Expand Down Expand Up @@ -564,7 +564,7 @@ public boolean compare(T[] a1, T[] a2) {

private static final Object NULL_KEY = new Object();
// A guardsatisfied.location.disallowed error is issued for the cast.
@SuppressWarnings({"cast.unsafe", "guardsatisfied.location.disallowed"})
@SuppressWarnings({"cast.incompatible", "guardsatisfied.location.disallowed"})
private static @GuardSatisfied(1) Object maskNull(@GuardSatisfied(1) Object key) {
return (key == null ? (@GuardSatisfied(1) Object) NULL_KEY : key);
}
Expand Down
2 changes: 2 additions & 0 deletions checker/tests/lock/Strings.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ void StringIsGBnothing(
@GuardSatisfied Object o3,
@GuardedByBottom Object o4) {
String s1 = (String) o1;
// :: error: (cast.incompatible)
String s2 = (String) o2;
// :: error: (cast.incompatible)
String s3 = (String) o3;
String s4 = (String) o4; // OK
}
Expand Down
4 changes: 2 additions & 2 deletions checker/tests/signedness/CharCast.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ void m(@SignedPositive int i) {

void m1(short s) {
int x = s;
// :: warning: (cast.unsafe)
// :: error: (cast.incompatible)
char c = (char) x;
}

void m2(int i) {
int x = (short) i;
// :: warning: (cast.unsafe)
// :: error: (cast.incompatible)
char c = (char) x;
}

Expand Down
2 changes: 2 additions & 0 deletions checker/tests/signedness/CharToFloat.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

public class CharToFloat {
void castCharacter(Object o) {
// :: error: (cast.incompatible)
floatParameter((Character) o);
// :: error: (cast.incompatible)
doubleParameter((Character) o);
}

Expand Down
2 changes: 1 addition & 1 deletion checker/tests/signedness/PrimitiveCasts.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class PrimitiveCasts {

void shortToChar1(short s) {
// :: warning: (cast.unsafe)
// :: error: (cast.incompatible)
char c = (char) s;
}

Expand Down
12 changes: 6 additions & 6 deletions checker/tests/signedness/WideningConversion.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ void plus() {

char c;
c = (char) (c1 + c2);
// :: warning: (cast.unsafe)
// :: error: (cast.incompatible)
c = (char) (c1 + i2);
// :: warning: (cast.unsafe)
// :: error: (cast.incompatible)
c = (char) (i1 + c2);
// :: warning: (cast.unsafe)
// :: error: (cast.incompatible)
c = (char) (i1 + i2);

c = (char) (c1 + c2);
// :: warning: (cast.unsafe)
// :: error: (cast.incompatible)
c = (char) (c1 + si2);
// :: warning: (cast.unsafe)
// :: error: (cast.incompatible)
c = (char) (si1 + c2);
// :: warning: (cast.unsafe)
// :: error: (cast.incompatible)
c = (char) (si1 + si2);

c = (char) (c1 + c2);
Expand Down
Loading