diff --git a/src/main/java/io/appium/java_client/remote/NewAppiumSessionPayload.java b/src/main/java/io/appium/java_client/remote/NewAppiumSessionPayload.java index 73dedeac8..18cb2f3ab 100644 --- a/src/main/java/io/appium/java_client/remote/NewAppiumSessionPayload.java +++ b/src/main/java/io/appium/java_client/remote/NewAppiumSessionPayload.java @@ -194,6 +194,7 @@ private void validate() throws IOException { throw new IllegalArgumentException("First match w3c capabilities is zero length"); } + //noinspection ResultOfMethodCallIgnored firsts.stream() .peek(map -> { Set overlap = Sets.intersection(always.keySet(), map.keySet()); @@ -256,14 +257,12 @@ public void writeTo(Appendable appendable) throws IOException { json.name(CAPABILITIES); json.beginObject(); - json.name(ALWAYS_MATCH); - getW3C().forEach(json::write); - + // Then write everything into the w3c payload. Because of the way we do this, it's easiest + // to just populate the "firstMatch" section. The spec says it's fine to omit the + // "alwaysMatch" field, so we do this. json.name(FIRST_MATCH); json.beginArray(); - //noinspection unchecked - json.beginObject(); - json.endObject(); + getW3C().forEach(json::write); json.endArray(); json.endObject(); // Close "capabilities" object @@ -291,7 +290,7 @@ private void writeMetaData(JsonOutput out) throws IOException { default: out.name(name); - out.write(input.read(Object.class)); + out.write(input.read(Object.class)); break; } } @@ -437,8 +436,7 @@ public Object setValue(Object value) { return null; } - Map toReturn = new TreeMap<>(); - toReturn.putAll(capabilities); + Map toReturn = new TreeMap<>(capabilities); // Platform name if (capabilities.containsKey(PLATFORM) && !capabilities.containsKey(PLATFORM_NAME)) {