diff --git a/java/src/org/openqa/selenium/devtools/CdpClientGenerator.java b/java/src/org/openqa/selenium/devtools/CdpClientGenerator.java index f38869992733a..1d34dd66a2816 100644 --- a/java/src/org/openqa/selenium/devtools/CdpClientGenerator.java +++ b/java/src/org/openqa/selenium/devtools/CdpClientGenerator.java @@ -17,6 +17,7 @@ package org.openqa.selenium.devtools; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.file.FileVisitResult.CONTINUE; import static java.util.Collections.unmodifiableMap; import static java.util.stream.Collectors.joining; @@ -176,8 +177,11 @@ public void parse(T target, Map json) { } private static class BaseSpec { + // it seems `name` is always filled from JSON + @SuppressWarnings({"NotNullFieldNotInitialized", "InstanceVariableMayNotBeInitialized"}) protected String name; - protected String description; + + protected @Nullable String description; protected boolean experimental; protected boolean deprecated; } @@ -343,7 +347,7 @@ private void dumpMainClass(Path target) { ensureFileDoesNotExists(commandFile); try { - Files.write(commandFile, unit.toString().getBytes()); + Files.write(commandFile, unit.toString().getBytes(UTF_8)); } catch (IOException e) { throw new UncheckedIOException(e); } @@ -426,7 +430,7 @@ public void dumpTo(Path target) { ensureFileDoesNotExists(eventFile); try { - Files.write(eventFile, unit.toString().getBytes()); + Files.write(eventFile, unit.toString().getBytes(UTF_8)); } catch (IOException e) { throw new UncheckedIOException(e); } @@ -540,7 +544,7 @@ public void dumpTo(Path target) { ensureFileDoesNotExists(typeFile); try { - Files.write(typeFile, unit.toString().getBytes()); + Files.write(typeFile, unit.toString().getBytes(UTF_8)); } catch (IOException e) { throw new UncheckedIOException(e); } @@ -766,7 +770,7 @@ private interface IType { String getJavaDefaultValue(); - TypeDeclaration toTypeDeclaration(); + @Nullable TypeDeclaration toTypeDeclaration(); String getMapper(); } @@ -1240,7 +1244,10 @@ public String getMapper() { } private static class ArrayType implements IType { + // it seems `name` is always filled from JSON + @SuppressWarnings({"NotNullFieldNotInitialized", "InstanceVariableMayNotBeInitialized"}) private IType itemType; + private final String name; public ArrayType(String name) { @@ -1402,7 +1409,10 @@ private static void ensureFileDoesNotExists(Path file) { } } - private static String capitalize(String text) { + private static String capitalize(@Nullable String text) { + if (text == null) { + return ""; + } return text.substring(0, 1).toUpperCase() + text.substring(1); } @@ -1415,9 +1425,6 @@ private static String toJavaConstant(String text) { } private static String sanitizeJavadoc(String description) { - if (description == null) { - return null; - } // Escape */ sequences which would prematurely close the JavaDoc comment return description.replace("*/", "*/"); } diff --git a/java/src/org/openqa/selenium/devtools/Command.java b/java/src/org/openqa/selenium/devtools/Command.java index adcf87c0389e7..8aeca8f09e368 100644 --- a/java/src/org/openqa/selenium/devtools/Command.java +++ b/java/src/org/openqa/selenium/devtools/Command.java @@ -35,7 +35,8 @@ public Command(String method, Map params) { } public Command(String method, Map params, Type typeOfX) { - this(method, params, input -> input.read(Require.nonNull("Type to convert to", typeOfX))); + this( + method, params, input -> input.readNonNull(Require.nonNull("Type to convert to", typeOfX))); } public Command(String method, Map params, Function mapper) { @@ -73,7 +74,10 @@ public boolean getSendsResponse() { /** * Some CDP commands do not appear to send responses, and so are really hard to deal with. Work * around that by flagging those commands. + * + * @deprecated Not needed. All CDP commands return something, at least empty map. */ + @Deprecated public Command doesNotSendResponse() { return new Command<>(method, params, mapper, false); } diff --git a/java/src/org/openqa/selenium/devtools/Connection.java b/java/src/org/openqa/selenium/devtools/Connection.java index 7bdfb064e9d32..90194266957ab 100644 --- a/java/src/org/openqa/selenium/devtools/Connection.java +++ b/java/src/org/openqa/selenium/devtools/Connection.java @@ -47,6 +47,7 @@ import java.util.function.Consumer; import java.util.logging.Level; import java.util.logging.Logger; +import org.jspecify.annotations.Nullable; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.devtools.idealized.target.model.SessionID; import org.openqa.selenium.internal.Either; @@ -90,7 +91,6 @@ public Connection(HttpClient client, String url) { } public Connection(HttpClient client, String url, ClientConfig clientConfig) { - ; this.client = Require.nonNull("HTTP client", client); this.wsConfig = wsClientConfig(clientConfig, url); this.socket = this.client.openSocket(new HttpRequest(GET, wsConfig.baseUri()), new Listener()); @@ -117,7 +117,7 @@ private static ClientConfig wsClientConfig(ClientConfig clientConfig, String uri } } - private static class NamedConsumer implements Consumer { + private static final class NamedConsumer implements Consumer { private final String name; private final Consumer delegate; @@ -142,7 +142,7 @@ public String toString() { } } - public CompletableFuture send(SessionID sessionId, Command command) { + public CompletableFuture send(@Nullable SessionID sessionId, Command command) { long id = NEXT_ID.getAndIncrement(); CompletableFuture result = new CompletableFuture<>(); @@ -185,13 +185,16 @@ public CompletableFuture send(SessionID sessionId, Command command) { socket.sendText(json); if (!command.getSendsResponse()) { + // As far as I see, it never happens. + // All DevTools commands return something - at least empty map. + //noinspection DataFlowIssue result.complete(null); } return result; } - public X sendAndWait(SessionID sessionId, Command command, Duration timeout) { + public X sendAndWait(@Nullable SessionID sessionId, Command command, Duration timeout) { try { CompletableFuture future = send(sessionId, command); return future.get(timeout.toMillis(), MILLISECONDS); diff --git a/java/src/org/openqa/selenium/devtools/ConverterFunctions.java b/java/src/org/openqa/selenium/devtools/ConverterFunctions.java index 054b2010b5a1b..579da57223100 100644 --- a/java/src/org/openqa/selenium/devtools/ConverterFunctions.java +++ b/java/src/org/openqa/selenium/devtools/ConverterFunctions.java @@ -38,7 +38,7 @@ public class ConverterFunctions { Require.nonNull("Read callback", read); return input -> { - @Nullable X value = null; + X value = null; input.beginObject(); while (input.hasNext()) { diff --git a/java/src/org/openqa/selenium/devtools/DevTools.java b/java/src/org/openqa/selenium/devtools/DevTools.java index c29fb7bc7a314..110d8530ad35b 100644 --- a/java/src/org/openqa/selenium/devtools/DevTools.java +++ b/java/src/org/openqa/selenium/devtools/DevTools.java @@ -32,7 +32,6 @@ import java.util.function.Function; import java.util.logging.Level; import java.util.logging.Logger; -import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; import org.openqa.selenium.WebDriver; import org.openqa.selenium.devtools.idealized.Domains; @@ -47,8 +46,8 @@ public class DevTools implements Closeable { private final Domains protocol; private final Duration timeout = Duration.ofSeconds(30); private final Connection connection; - private volatile String windowHandle; - private volatile SessionID cdpSession; + private volatile @Nullable String windowHandle; + private volatile @Nullable SessionID cdpSession; public DevTools(Function protocol, Connection connection) { this.connection = Require.nonNull("WebSocket connection", connection); @@ -66,7 +65,8 @@ public void close() { } public void disconnectSession() { - if (cdpSession != null) { + SessionID id = cdpSession; + if (id != null) { try { // ensure network interception does cancel the wait for responses getDomains().network().disable(); @@ -75,7 +75,6 @@ public void disconnectSession() { LOG.log(Level.WARNING, "Exception while disabling network", e); } - SessionID id = cdpSession; cdpSession = null; windowHandle = null; @@ -168,7 +167,7 @@ public void createSession(@Nullable String windowHandle) { attachToWindow(windowHandle); } - private void attachToWindow(String windowHandle) { + private void attachToWindow(@Nullable String windowHandle) { TargetID targetId = findTarget(windowHandle); attachToTarget(targetId); this.windowHandle = windowHandle; @@ -210,8 +209,7 @@ private void attachToTarget(TargetID targetId) { } } - @NonNull - private TargetID findTarget(String windowHandle) { + private TargetID findTarget(@Nullable String windowHandle) { // Figure out the targets. List infos = connection.sendAndWait(cdpSession, getDomains().target().getTargets(), timeout); @@ -231,6 +229,7 @@ private Throwable unwrapCause(ExecutionException e) { return e.getCause() != null ? e.getCause() : e; } + @Nullable public SessionID getCdpSession() { return cdpSession; } diff --git a/java/src/org/openqa/selenium/devtools/DevToolsException.java b/java/src/org/openqa/selenium/devtools/DevToolsException.java index ba58cb9c06d7a..eedb38062f6ec 100644 --- a/java/src/org/openqa/selenium/devtools/DevToolsException.java +++ b/java/src/org/openqa/selenium/devtools/DevToolsException.java @@ -17,22 +17,22 @@ package org.openqa.selenium.devtools; -import org.jspecify.annotations.NullMarked; +import static java.util.Objects.requireNonNullElseGet; + import org.jspecify.annotations.Nullable; import org.openqa.selenium.WebDriverException; -@NullMarked public class DevToolsException extends WebDriverException { - public DevToolsException(@Nullable Throwable cause) { - this(cause.getMessage(), cause); + public DevToolsException(Throwable cause) { + this(requireNonNullElseGet(cause.getMessage(), cause::toString), cause); } - public DevToolsException(@Nullable String message) { + public DevToolsException(String message) { this(message, null); } - public DevToolsException(@Nullable String message, @Nullable Throwable cause) { + public DevToolsException(String message, @Nullable Throwable cause) { super(message, cause); addInfo(WebDriverException.DRIVER_INFO, "DevTools Connection"); } diff --git a/java/src/org/openqa/selenium/devtools/RequestFailedException.java b/java/src/org/openqa/selenium/devtools/RequestFailedException.java index 322d610b28951..6ffef0c946fc3 100644 --- a/java/src/org/openqa/selenium/devtools/RequestFailedException.java +++ b/java/src/org/openqa/selenium/devtools/RequestFailedException.java @@ -17,7 +17,6 @@ package org.openqa.selenium.devtools; -import org.jspecify.annotations.NullMarked; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.remote.http.Filter; import org.openqa.selenium.remote.http.HttpHandler; @@ -27,5 +26,4 @@ * browser fails to send a HTTP request. It can be caught in a {@link Filter} to handle the error * by, for example, returning a custom HTTP response. */ -@NullMarked public class RequestFailedException extends WebDriverException {} diff --git a/java/src/org/openqa/selenium/devtools/events/CdpEventTypes.java b/java/src/org/openqa/selenium/devtools/events/CdpEventTypes.java index 372c3d06687c1..a5afd71fc5fe3 100644 --- a/java/src/org/openqa/selenium/devtools/events/CdpEventTypes.java +++ b/java/src/org/openqa/selenium/devtools/events/CdpEventTypes.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; @@ -62,7 +63,7 @@ public void initializeListener(WebDriver webDriver) { }; } - public static EventType domMutation(Consumer handler) { + public static EventType domMutation(Consumer<@Nullable DomMutationEvent> handler) { Require.nonNull("Handler", handler); String script = Read.resourceAsString("/org/openqa/selenium/devtools/mutation-listener.js"); diff --git a/java/src/org/openqa/selenium/devtools/events/package-info.java b/java/src/org/openqa/selenium/devtools/events/package-info.java new file mode 100644 index 0000000000000..d5cef07efde14 --- /dev/null +++ b/java/src/org/openqa/selenium/devtools/events/package-info.java @@ -0,0 +1,21 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +@NullMarked +package org.openqa.selenium.devtools.events; + +import org.jspecify.annotations.NullMarked; diff --git a/java/src/org/openqa/selenium/devtools/idealized/Network.java b/java/src/org/openqa/selenium/devtools/idealized/Network.java index 949811311a6be..2eed867917208 100644 --- a/java/src/org/openqa/selenium/devtools/idealized/Network.java +++ b/java/src/org/openqa/selenium/devtools/idealized/Network.java @@ -19,6 +19,7 @@ import static java.net.HttpURLConnection.HTTP_OK; import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.Objects.requireNonNull; import static java.util.logging.Level.WARNING; import java.net.URI; @@ -37,6 +38,7 @@ import java.util.function.Predicate; import java.util.function.Supplier; import java.util.logging.Logger; +import org.jspecify.annotations.Nullable; import org.openqa.selenium.Credentials; import org.openqa.selenium.TimeoutException; import org.openqa.selenium.UsernameAndPassword; @@ -151,7 +153,6 @@ public void addAuthHandler( prepareToInterceptTraffic(); } - @SuppressWarnings("SuspiciousMethodCalls") public void resetNetworkFilter() { filter = defaultFilter; } @@ -216,7 +217,7 @@ public void prepareToInterceptTraffic() { Either message = createSeMessages(pausedRequest); if (message.isRight()) { - HttpResponse res = message.right(); + HttpResponse res = requireNonNull(message.right()); CompletableFuture future = pendingResponses.remove(id); if (future == null) { @@ -310,9 +311,9 @@ protected HttpMethod convertFromCdpHttpMethod(String method) { protected HttpResponse createHttpResponse( Optional statusCode, - String body, - Boolean bodyIsBase64Encoded, - List> headers) { + @Nullable String body, + @Nullable Boolean bodyIsBase64Encoded, + List> headers) { Contents.Supplier content; if (body == null) { diff --git a/java/src/org/openqa/selenium/devtools/idealized/browser/model/package-info.java b/java/src/org/openqa/selenium/devtools/idealized/browser/model/package-info.java new file mode 100644 index 0000000000000..6988e29b3ba26 --- /dev/null +++ b/java/src/org/openqa/selenium/devtools/idealized/browser/model/package-info.java @@ -0,0 +1,21 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +@NullMarked +package org.openqa.selenium.devtools.idealized.browser.model; + +import org.jspecify.annotations.NullMarked; diff --git a/java/src/org/openqa/selenium/devtools/idealized/log/model/package-info.java b/java/src/org/openqa/selenium/devtools/idealized/log/model/package-info.java new file mode 100644 index 0000000000000..a12de4c826664 --- /dev/null +++ b/java/src/org/openqa/selenium/devtools/idealized/log/model/package-info.java @@ -0,0 +1,21 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +@NullMarked +package org.openqa.selenium.devtools.idealized.log.model; + +import org.jspecify.annotations.NullMarked; diff --git a/java/src/org/openqa/selenium/devtools/idealized/log/package-info.java b/java/src/org/openqa/selenium/devtools/idealized/log/package-info.java new file mode 100644 index 0000000000000..eb8d488256630 --- /dev/null +++ b/java/src/org/openqa/selenium/devtools/idealized/log/package-info.java @@ -0,0 +1,21 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +@NullMarked +package org.openqa.selenium.devtools.idealized.log; + +import org.jspecify.annotations.NullMarked; diff --git a/java/src/org/openqa/selenium/devtools/idealized/package-info.java b/java/src/org/openqa/selenium/devtools/idealized/package-info.java new file mode 100644 index 0000000000000..4dcf6a26f93db --- /dev/null +++ b/java/src/org/openqa/selenium/devtools/idealized/package-info.java @@ -0,0 +1,21 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +@NullMarked +package org.openqa.selenium.devtools.idealized; + +import org.jspecify.annotations.NullMarked; diff --git a/java/src/org/openqa/selenium/devtools/idealized/runtime/model/RemoteObject.java b/java/src/org/openqa/selenium/devtools/idealized/runtime/model/RemoteObject.java index d4f7722263de3..2dbb9630d1ac8 100644 --- a/java/src/org/openqa/selenium/devtools/idealized/runtime/model/RemoteObject.java +++ b/java/src/org/openqa/selenium/devtools/idealized/runtime/model/RemoteObject.java @@ -17,12 +17,14 @@ package org.openqa.selenium.devtools.idealized.runtime.model; +import org.jspecify.annotations.Nullable; + public class RemoteObject { private final String type; - private final Object value; + private final @Nullable Object value; - public RemoteObject(String type, Object value) { + public RemoteObject(String type, @Nullable Object value) { this.type = type; this.value = value; } @@ -38,6 +40,7 @@ public String getType() { return type; } + @Nullable public Object getValue() { return value; } diff --git a/java/src/org/openqa/selenium/devtools/idealized/runtime/model/package-info.java b/java/src/org/openqa/selenium/devtools/idealized/runtime/model/package-info.java new file mode 100644 index 0000000000000..90e68397e2e71 --- /dev/null +++ b/java/src/org/openqa/selenium/devtools/idealized/runtime/model/package-info.java @@ -0,0 +1,21 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +@NullMarked +package org.openqa.selenium.devtools.idealized.runtime.model; + +import org.jspecify.annotations.NullMarked; diff --git a/java/src/org/openqa/selenium/devtools/idealized/target/model/TargetInfo.java b/java/src/org/openqa/selenium/devtools/idealized/target/model/TargetInfo.java index 6451b73b1b861..d3a54ef04961a 100644 --- a/java/src/org/openqa/selenium/devtools/idealized/target/model/TargetInfo.java +++ b/java/src/org/openqa/selenium/devtools/idealized/target/model/TargetInfo.java @@ -20,6 +20,7 @@ import java.util.Optional; import org.openqa.selenium.Beta; import org.openqa.selenium.devtools.idealized.browser.model.BrowserContextID; +import org.openqa.selenium.internal.Require; import org.openqa.selenium.json.JsonInput; public class TargetInfo { @@ -42,11 +43,11 @@ public TargetInfo( Boolean attached, Optional openerId, Optional browserContextId) { - this.targetId = java.util.Objects.requireNonNull(targetId, "targetId is required"); - this.type = java.util.Objects.requireNonNull(type, "type is required"); - this.title = java.util.Objects.requireNonNull(title, "title is required"); - this.url = java.util.Objects.requireNonNull(url, "url is required"); - this.attached = java.util.Objects.requireNonNull(attached, "attached is required"); + this.targetId = Require.nonNull("targetId", targetId); + this.type = Require.nonNull("type", type); + this.title = Require.nonNull("title", title); + this.url = Require.nonNull("url", url); + this.attached = Require.nonNull("attached", attached); this.openerId = openerId; this.browserContextId = browserContextId; } @@ -82,6 +83,7 @@ public Optional getBrowserContextId() { return browserContextId; } + @SuppressWarnings("DataFlowIssue") private static TargetInfo fromJson(JsonInput input) { TargetID targetId = null; String type = null; diff --git a/java/src/org/openqa/selenium/devtools/idealized/target/model/package-info.java b/java/src/org/openqa/selenium/devtools/idealized/target/model/package-info.java new file mode 100644 index 0000000000000..de674415b30b4 --- /dev/null +++ b/java/src/org/openqa/selenium/devtools/idealized/target/model/package-info.java @@ -0,0 +1,21 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +@NullMarked +package org.openqa.selenium.devtools.idealized.target.model; + +import org.jspecify.annotations.NullMarked; diff --git a/java/src/org/openqa/selenium/devtools/idealized/target/package-info.java b/java/src/org/openqa/selenium/devtools/idealized/target/package-info.java new file mode 100644 index 0000000000000..00401925522f0 --- /dev/null +++ b/java/src/org/openqa/selenium/devtools/idealized/target/package-info.java @@ -0,0 +1,21 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +@NullMarked +package org.openqa.selenium.devtools.idealized.target; + +import org.jspecify.annotations.NullMarked; diff --git a/java/src/org/openqa/selenium/devtools/noop/package-info.java b/java/src/org/openqa/selenium/devtools/noop/package-info.java new file mode 100644 index 0000000000000..d59564ae18c2e --- /dev/null +++ b/java/src/org/openqa/selenium/devtools/noop/package-info.java @@ -0,0 +1,21 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +@NullMarked +package org.openqa.selenium.devtools.noop; + +import org.jspecify.annotations.NullMarked; diff --git a/java/src/org/openqa/selenium/devtools/v143/BUILD.bazel b/java/src/org/openqa/selenium/devtools/v143/BUILD.bazel index c16d20745a71e..819cfbb8ae8e4 100644 --- a/java/src/org/openqa/selenium/devtools/v143/BUILD.bazel +++ b/java/src/org/openqa/selenium/devtools/v143/BUILD.bazel @@ -1,3 +1,4 @@ +load("@rules_jvm_external//:defs.bzl", "artifact") load("//common:defs.bzl", "copy_file") load("//java:defs.bzl", "java_export", "java_library") load("//java:version.bzl", "SE_VERSION") @@ -27,6 +28,7 @@ java_export( "//java/src/org/openqa/selenium:core", "//java/src/org/openqa/selenium/json", "//java/src/org/openqa/selenium/remote", + artifact("org.jspecify:jspecify"), ], ) @@ -42,6 +44,7 @@ java_library( "//java/src/org/openqa/selenium:core", "//java/src/org/openqa/selenium/json", "//java/src/org/openqa/selenium/remote", + artifact("org.jspecify:jspecify"), ], ) diff --git a/java/src/org/openqa/selenium/devtools/v143/package-info.java b/java/src/org/openqa/selenium/devtools/v143/package-info.java new file mode 100644 index 0000000000000..ad7c75636057c --- /dev/null +++ b/java/src/org/openqa/selenium/devtools/v143/package-info.java @@ -0,0 +1,21 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +@NullMarked +package org.openqa.selenium.devtools.v143; + +import org.jspecify.annotations.NullMarked; diff --git a/java/src/org/openqa/selenium/devtools/v144/BUILD.bazel b/java/src/org/openqa/selenium/devtools/v144/BUILD.bazel index 885b9016ea619..19226eabfe7ca 100644 --- a/java/src/org/openqa/selenium/devtools/v144/BUILD.bazel +++ b/java/src/org/openqa/selenium/devtools/v144/BUILD.bazel @@ -1,3 +1,4 @@ +load("@rules_jvm_external//:defs.bzl", "artifact") load("//common:defs.bzl", "copy_file") load("//java:defs.bzl", "java_export", "java_library") load("//java:version.bzl", "SE_VERSION") @@ -27,6 +28,7 @@ java_export( "//java/src/org/openqa/selenium:core", "//java/src/org/openqa/selenium/json", "//java/src/org/openqa/selenium/remote", + artifact("org.jspecify:jspecify"), ], ) @@ -42,6 +44,7 @@ java_library( "//java/src/org/openqa/selenium:core", "//java/src/org/openqa/selenium/json", "//java/src/org/openqa/selenium/remote", + artifact("org.jspecify:jspecify"), ], ) diff --git a/java/src/org/openqa/selenium/devtools/v144/package-info.java b/java/src/org/openqa/selenium/devtools/v144/package-info.java new file mode 100644 index 0000000000000..2b3fd2eb579b6 --- /dev/null +++ b/java/src/org/openqa/selenium/devtools/v144/package-info.java @@ -0,0 +1,21 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +@NullMarked +package org.openqa.selenium.devtools.v144; + +import org.jspecify.annotations.NullMarked; diff --git a/java/src/org/openqa/selenium/devtools/v145/BUILD.bazel b/java/src/org/openqa/selenium/devtools/v145/BUILD.bazel index 09605c4cd51ba..de0c2b7ccd6e6 100644 --- a/java/src/org/openqa/selenium/devtools/v145/BUILD.bazel +++ b/java/src/org/openqa/selenium/devtools/v145/BUILD.bazel @@ -1,3 +1,4 @@ +load("@rules_jvm_external//:defs.bzl", "artifact") load("//common:defs.bzl", "copy_file") load("//java:defs.bzl", "java_export", "java_library") load("//java:version.bzl", "SE_VERSION") @@ -27,6 +28,7 @@ java_export( "//java/src/org/openqa/selenium:core", "//java/src/org/openqa/selenium/json", "//java/src/org/openqa/selenium/remote", + artifact("org.jspecify:jspecify"), ], ) @@ -42,6 +44,7 @@ java_library( "//java/src/org/openqa/selenium:core", "//java/src/org/openqa/selenium/json", "//java/src/org/openqa/selenium/remote", + artifact("org.jspecify:jspecify"), ], ) diff --git a/java/src/org/openqa/selenium/devtools/v145/package-info.java b/java/src/org/openqa/selenium/devtools/v145/package-info.java new file mode 100644 index 0000000000000..9af117579c531 --- /dev/null +++ b/java/src/org/openqa/selenium/devtools/v145/package-info.java @@ -0,0 +1,21 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +@NullMarked +package org.openqa.selenium.devtools.v145; + +import org.jspecify.annotations.NullMarked; diff --git a/java/test/org/openqa/selenium/devtools/BUILD.bazel b/java/test/org/openqa/selenium/devtools/BUILD.bazel index 9664a5f059000..7c0b8f68509b9 100644 --- a/java/test/org/openqa/selenium/devtools/BUILD.bazel +++ b/java/test/org/openqa/selenium/devtools/BUILD.bazel @@ -15,6 +15,7 @@ java_test_suite( "//java/src/org/openqa/selenium/remote", artifact("org.junit.jupiter:junit-jupiter-api"), artifact("org.assertj:assertj-core"), + artifact("org.jspecify:jspecify"), ] + JUNIT5_DEPS, ) @@ -46,6 +47,7 @@ java_selenium_test_suite( artifact("com.google.guava:guava"), artifact("org.junit.jupiter:junit-jupiter-api"), artifact("org.assertj:assertj-core"), + artifact("org.jspecify:jspecify"), ] + JUNIT5_DEPS, ) @@ -67,5 +69,6 @@ java_library( "//java/test/org/openqa/selenium/testing/drivers", artifact("org.junit.jupiter:junit-jupiter-api"), artifact("org.assertj:assertj-core"), + artifact("org.jspecify:jspecify"), ] + JUNIT5_DEPS, ) diff --git a/java/test/org/openqa/selenium/devtools/idealized/runtime/model/RemoteObjectTest.java b/java/test/org/openqa/selenium/devtools/idealized/runtime/model/RemoteObjectTest.java new file mode 100644 index 0000000000000..951fb6130116b --- /dev/null +++ b/java/test/org/openqa/selenium/devtools/idealized/runtime/model/RemoteObjectTest.java @@ -0,0 +1,57 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.openqa.selenium.devtools.idealized.runtime.model; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; +import org.junit.jupiter.api.Test; + +class RemoteObjectTest { + @Test + void toString_embracesStringValueInQuotes() { + assertThat(new RemoteObject("foo", "bar")) + .hasToString( + """ + "bar" + """ + .trim()); + } + + @Test + void toString_escapesQuotesInStringValue() { + assertThat(new RemoteObject("foo", "bar\"baz")) + .hasToString( + """ + "bar\\"baz" + """ + .trim()); + } + + @Test + void toString_withNonStringValues() { + assertThat(new RemoteObject("foo", 42)).hasToString("42"); + assertThat(new RemoteObject("foo", false)).hasToString("false"); + assertThat(new RemoteObject("foo", List.of("a", "b", "c"))).hasToString("[a, b, c]"); + } + + @Test + void toString_withNullValue() { + assertThat(new RemoteObject("foo", null)).hasToString("null"); + } +} diff --git a/java/test/org/openqa/selenium/devtools/idealized/runtime/model/package-info.java b/java/test/org/openqa/selenium/devtools/idealized/runtime/model/package-info.java new file mode 100644 index 0000000000000..90e68397e2e71 --- /dev/null +++ b/java/test/org/openqa/selenium/devtools/idealized/runtime/model/package-info.java @@ -0,0 +1,21 @@ +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +@NullMarked +package org.openqa.selenium.devtools.idealized.runtime.model; + +import org.jspecify.annotations.NullMarked;