diff options
| author | John Reck <jreck@google.com> | 2017-11-09 21:14:24 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-11-09 21:14:24 +0000 |
| commit | cbfc6373e3a6e0b7f3d35701990baba085dea540 (patch) | |
| tree | 35713ec686bf9c0755ef0817fcb4d2add91c5a95 /core/java/android | |
| parent | 17da6d2a3fe3445fcae641fef556597c9349a084 (diff) | |
| parent | 3e5aa7ccbaef48d2d8d174909d04f04a7e58729d (diff) | |
Merge "Throw exception on non-finite floats"
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/view/View.java | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index c043dcacf11f..e12c0b0d93b8 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -14218,6 +14218,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ public void setScaleX(float scaleX) { if (scaleX != getScaleX()) { + requireIsFinite(scaleX, "scaleX"); invalidateViewProperty(true, false); mRenderNode.setScaleX(scaleX); invalidateViewProperty(false, true); @@ -14254,6 +14255,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ public void setScaleY(float scaleY) { if (scaleY != getScaleY()) { + requireIsFinite(scaleY, "scaleY"); invalidateViewProperty(true, false); mRenderNode.setScaleY(scaleY); invalidateViewProperty(false, true); @@ -14803,6 +14805,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } } + private static void requireIsFinite(float transform, String propertyName) { + if (Float.isNaN(transform)) { + throw new IllegalArgumentException("Cannot set '" + propertyName + "' to Float.NaN"); + } + if (Float.isInfinite(transform)) { + throw new IllegalArgumentException("Cannot set '" + propertyName + "' to infinity"); + } + } + /** * The visual x position of this view, in pixels. This is equivalent to the * {@link #setTranslationX(float) translationX} property plus the current @@ -14889,6 +14900,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ public void setElevation(float elevation) { if (elevation != getElevation()) { + requireIsFinite(elevation, "elevation"); invalidateViewProperty(true, false); mRenderNode.setElevation(elevation); invalidateViewProperty(false, true); @@ -14981,6 +14993,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ public void setTranslationZ(float translationZ) { if (translationZ != getTranslationZ()) { + requireIsFinite(translationZ, "translationZ"); invalidateViewProperty(true, false); mRenderNode.setTranslationZ(translationZ); invalidateViewProperty(false, true); |
