From 2156a17b9a9242458270eb6e14dbfbee86bff2d1 Mon Sep 17 00:00:00 2001 From: Jia Hao Date: Wed, 8 Nov 2023 01:41:25 +0000 Subject: [PATCH] Fix narrowing conversion lint (flutter/engine#47740) Internally we have a lint that surfaces this as a warning. Googlers, please refer to go/al-rule/NarrowingConversion. Related: b/309552840 When we do: ``` coords.toolMajor = (float) (double) coordsList.get(3) * density; ``` `coordsList.get(3)` is casted to a `double`, then a `float`, before the multiplication happens. I don't think this is intentional. The intention of the code here seems to be: - Cast to a `double`: `coordsList` is a `List` so the cast narrows the value - Cast to a `float`: To fit the resulting value into [`coords.toolMajor`](https://developer.android.com/reference/android/view/MotionEvent.PointerCoords#toolMajor), which is a `float`. As such, add parenthesis to address this. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../plugin/platform/PlatformViewsController.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java index 820a8629b4..6db1564f58 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java @@ -1027,12 +1027,12 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega coords.orientation = (float) (double) coordsList.get(0); coords.pressure = (float) (double) coordsList.get(1); coords.size = (float) (double) coordsList.get(2); - coords.toolMajor = (float) (double) coordsList.get(3) * density; - coords.toolMinor = (float) (double) coordsList.get(4) * density; - coords.touchMajor = (float) (double) coordsList.get(5) * density; - coords.touchMinor = (float) (double) coordsList.get(6) * density; - coords.x = (float) (double) coordsList.get(7) * density; - coords.y = (float) (double) coordsList.get(8) * density; + coords.toolMajor = (float) ((double) coordsList.get(3) * density); + coords.toolMinor = (float) ((double) coordsList.get(4) * density); + coords.touchMajor = (float) ((double) coordsList.get(5) * density); + coords.touchMinor = (float) ((double) coordsList.get(6) * density); + coords.x = (float) ((double) coordsList.get(7) * density); + coords.y = (float) ((double) coordsList.get(8) * density); return coords; }