From 5b3edbde20b446ecbfebe5d6ad0dcd735473ac75 Mon Sep 17 00:00:00 2001 From: Chet Haase Date: Wed, 22 Apr 2015 17:07:21 -0700 Subject: [PATCH] Add annotation to Rect.intersect() Failing to check the return result from intersect() can cause artifacts because the developer may assume that the rect has been changed to the intersection. In particular, when the two rects do not overlap, there is no change made to the source rect. Instead, the method simply returns false. When developers do not check that return value, they may use the source rect and get undefined results. This change adds the @CheckResults annotation that will cause a Lint warning when developers call this method without checking the return value. Change-Id: I476367d74e712038c248c2379fb124734298fcc1 --- graphics/java/android/graphics/Rect.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/graphics/java/android/graphics/Rect.java b/graphics/java/android/graphics/Rect.java index a9a8f37c6dae9..f036b19d22c34 100644 --- a/graphics/java/android/graphics/Rect.java +++ b/graphics/java/android/graphics/Rect.java @@ -16,6 +16,7 @@ package android.graphics; +import android.annotation.CheckResult; import android.os.Parcel; import android.os.Parcelable; @@ -389,6 +390,7 @@ public final class Rect implements Parcelable { * (and this rectangle is then set to that intersection) else * return false and do not change this rectangle. */ + @CheckResult public boolean intersect(int left, int top, int right, int bottom) { if (this.left < right && left < this.right && this.top < bottom && top < this.bottom) { if (this.left < left) this.left = left; @@ -411,6 +413,7 @@ public final class Rect implements Parcelable { * (and this rectangle is then set to that intersection) else * return false and do not change this rectangle. */ + @CheckResult public boolean intersect(Rect r) { return intersect(r.left, r.top, r.right, r.bottom); } @@ -427,6 +430,7 @@ public final class Rect implements Parcelable { * this rectangle to that intersection. If they do not, return * false and do not change this rectangle. */ + @CheckResult public boolean setIntersect(Rect a, Rect b) { if (a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom) { left = Math.max(a.left, b.left);