From 28a4be86a4858796db26b9aca9f07a75cc8ebd3c Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 21 Oct 2020 00:07:01 -0700 Subject: [PATCH] chore: suppress some of "unchecked cast" warnings (#25) --- .../java/com/microsoft/playwright/impl/ChannelOwner.java | 1 + .../java/com/microsoft/playwright/impl/Serialization.java | 6 ++++-- .../java/com/microsoft/playwright/impl/WaitableEvent.java | 2 ++ .../com/microsoft/playwright/TestPageExposeFunction.java | 3 +++ .../src/test/java/com/microsoft/playwright/TestPopup.java | 1 + .../src/test/java/com/microsoft/playwright/Utils.java | 1 + 6 files changed, 12 insertions(+), 2 deletions(-) diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/ChannelOwner.java b/playwright/src/main/java/com/microsoft/playwright/impl/ChannelOwner.java index f0776be4..21054dbf 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/ChannelOwner.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/ChannelOwner.java @@ -68,6 +68,7 @@ class ChannelOwner { connection.sendMessageNoWait(guid, method, params); } + @SuppressWarnings("unchecked") Deferred toDeferred(Waitable waitable) { return () -> { while (!waitable.isDone()) { diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java b/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java index 1ccfeefe..c6138eb4 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java @@ -79,6 +79,7 @@ class Serialization { result.a = list.toArray(new SerializedValue[0]); } else if (value instanceof Map) { List list = new ArrayList<>(); + @SuppressWarnings("unchecked") Map map = (Map) value; for (Map.Entry e : map.entrySet()) { SerializedValue.O o = new SerializedValue.O(); @@ -113,6 +114,7 @@ class Serialization { return result; } + @SuppressWarnings("unchecked") static T deserialize(SerializedValue value) { if (value.n != null) { if (value.n.doubleValue() == (double) value.n.intValue()) { @@ -142,14 +144,14 @@ class Serialization { } } if (value.a != null) { - List list = new ArrayList(); + List list = new ArrayList<>(); for (SerializedValue v : value.a) { list.add(deserialize(v)); } return (T) list; } if (value.o != null) { - Map map = new LinkedHashMap<>(); + Map map = new LinkedHashMap<>(); for (SerializedValue.O o : value.o) { map.put(o.k, deserialize(o.v)); } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/WaitableEvent.java b/playwright/src/main/java/com/microsoft/playwright/impl/WaitableEvent.java index 89c499d5..8ab9710d 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/WaitableEvent.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/WaitableEvent.java @@ -56,6 +56,8 @@ class WaitableEvent implements Waitable, List listeners.remove(type, this); } + @SuppressWarnings("unchecked") + @Override public ResultType get() { return (ResultType) event.data(); } diff --git a/playwright/src/test/java/com/microsoft/playwright/TestPageExposeFunction.java b/playwright/src/test/java/com/microsoft/playwright/TestPageExposeFunction.java index b3641dc0..bb7fa0e8 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestPageExposeFunction.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestPageExposeFunction.java @@ -136,6 +136,7 @@ public class TestPageExposeFunction { " }\n" + "}"); assertTrue(result instanceof Map); + @SuppressWarnings("unchecked") Map m = (Map) result; assertEquals("WOOF WOOF", m.get("message")); assertTrue(m.get("stack").contains("shouldThrowExceptionInPageContext")); @@ -202,7 +203,9 @@ public class TestPageExposeFunction { @Test void shouldWorkWithComplexObjects() { page.exposeFunction("complexObject", args -> { + @SuppressWarnings("unchecked") Map a = (Map) args[0]; + @SuppressWarnings("unchecked") Map b = (Map) args[1]; int sum = a.get("x") + b.get("x"); return mapOf("x", sum); diff --git a/playwright/src/test/java/com/microsoft/playwright/TestPopup.java b/playwright/src/test/java/com/microsoft/playwright/TestPopup.java index e0db971b..db9a8ba2 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestPopup.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestPopup.java @@ -106,6 +106,7 @@ public class TestPopup { @Test void shouldInheritExtraHeadersFromBrowserContext() throws ExecutionException, InterruptedException { + @SuppressWarnings("unchecked") BrowserContext context = browser.newContext(new Browser.NewContextOptions() .withExtraHTTPHeaders(mapOf("foo", "bar"))); Page page = context.newPage(); diff --git a/playwright/src/test/java/com/microsoft/playwright/Utils.java b/playwright/src/test/java/com/microsoft/playwright/Utils.java index 52a079d6..b13f3b90 100644 --- a/playwright/src/test/java/com/microsoft/playwright/Utils.java +++ b/playwright/src/test/java/com/microsoft/playwright/Utils.java @@ -20,6 +20,7 @@ import java.util.HashMap; import java.util.Map; class Utils { + @SuppressWarnings("unchecked") static Map mapOf(Object... entries) { Map result = new HashMap(); for (int i = 0; i + 1 < entries.length; i += 2) {