Rating: Disallow putting Float.NaN as star/percent values
When creating a Rating instance, invalid values shouldn't be allowed. However, Float.NaN passes the checks, which leads to creating invalid ones. This CL fixes the code. Bug: 173680971 Test: Passed CTS Change-Id: I629f1568a2efb0c324cc11e94969356c59298db8
This commit is contained in:
@@ -206,11 +206,12 @@ public final class Rating implements Parcelable {
|
||||
Log.e(TAG, "Invalid rating style (" + starRatingStyle + ") for a star rating");
|
||||
return null;
|
||||
}
|
||||
if ((starRating < 0.0f) || (starRating > maxRating)) {
|
||||
if (starRating >= 0.0f && starRating <= maxRating) {
|
||||
return new Rating(starRatingStyle, starRating);
|
||||
} else {
|
||||
Log.e(TAG, "Trying to set out of range star-based rating");
|
||||
return null;
|
||||
}
|
||||
return new Rating(starRatingStyle, starRating);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -221,11 +222,11 @@ public final class Rating implements Parcelable {
|
||||
* @return null if the rating is out of range, a new Rating instance otherwise.
|
||||
*/
|
||||
public static Rating newPercentageRating(float percent) {
|
||||
if ((percent < 0.0f) || (percent > 100.0f)) {
|
||||
if (percent >= 0.0f && percent <= 100.0f) {
|
||||
return new Rating(RATING_PERCENTAGE, percent);
|
||||
} else {
|
||||
Log.e(TAG, "Invalid percentage-based rating value");
|
||||
return null;
|
||||
} else {
|
||||
return new Rating(RATING_PERCENTAGE, percent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user