diff --git a/java/src/org/openqa/selenium/chromium/ChromiumDriver.java b/java/src/org/openqa/selenium/chromium/ChromiumDriver.java index 3a3ec3a1bdbc1..60f96c994fe9f 100644 --- a/java/src/org/openqa/selenium/chromium/ChromiumDriver.java +++ b/java/src/org/openqa/selenium/chromium/ChromiumDriver.java @@ -33,6 +33,7 @@ import java.util.function.Supplier; import java.util.logging.Level; import java.util.logging.Logger; +import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; import org.openqa.selenium.BuildInfo; import org.openqa.selenium.Capabilities; @@ -277,6 +278,7 @@ public void setFileDetector(FileDetector detector) { } @Override + @NullMarked public void onLogEvent(EventType kind) { Require.nonNull("Event type", kind); kind.initializeListener(this); diff --git a/java/src/org/openqa/selenium/events/BUILD.bazel b/java/src/org/openqa/selenium/events/BUILD.bazel index 6e0e34a1719d9..a545317a91719 100644 --- a/java/src/org/openqa/selenium/events/BUILD.bazel +++ b/java/src/org/openqa/selenium/events/BUILD.bazel @@ -1,4 +1,4 @@ -load("//java:defs.bzl", "java_library") +load("//java:defs.bzl", "artifact", "java_library") java_library( name = "events", @@ -13,5 +13,6 @@ java_library( "//java/src/org/openqa/selenium:core", "//java/src/org/openqa/selenium/json", "//java/src/org/openqa/selenium/status", + artifact("org.jspecify:jspecify"), ], ) diff --git a/java/src/org/openqa/selenium/events/local/BUILD.bazel b/java/src/org/openqa/selenium/events/local/BUILD.bazel index 9d3bec64b4122..88fa5fe1d0221 100644 --- a/java/src/org/openqa/selenium/events/local/BUILD.bazel +++ b/java/src/org/openqa/selenium/events/local/BUILD.bazel @@ -15,5 +15,6 @@ java_library( "//java/src/org/openqa/selenium/events", "//java/src/org/openqa/selenium/grid/config", artifact("com.google.guava:guava"), + artifact("org.jspecify:jspecify"), ], ) diff --git a/java/src/org/openqa/selenium/events/local/package-info.java b/java/src/org/openqa/selenium/events/local/package-info.java new file mode 100644 index 0000000000000..613ea814cc1a4 --- /dev/null +++ b/java/src/org/openqa/selenium/events/local/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.events.local; + +import org.jspecify.annotations.NullMarked; diff --git a/java/src/org/openqa/selenium/events/package-info.java b/java/src/org/openqa/selenium/events/package-info.java new file mode 100644 index 0000000000000..d1d8629c77899 --- /dev/null +++ b/java/src/org/openqa/selenium/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.events; + +import org.jspecify.annotations.NullMarked; diff --git a/java/src/org/openqa/selenium/events/zeromq/BUILD.bazel b/java/src/org/openqa/selenium/events/zeromq/BUILD.bazel index fff6405c66483..202abad603b7f 100644 --- a/java/src/org/openqa/selenium/events/zeromq/BUILD.bazel +++ b/java/src/org/openqa/selenium/events/zeromq/BUILD.bazel @@ -20,5 +20,6 @@ java_library( artifact("com.google.guava:guava"), artifact("dev.failsafe:failsafe"), artifact("org.zeromq:jeromq"), + artifact("org.jspecify:jspecify"), ], ) diff --git a/java/src/org/openqa/selenium/events/zeromq/UnboundZmqEventBus.java b/java/src/org/openqa/selenium/events/zeromq/UnboundZmqEventBus.java index e3d255bde576e..c841dcf89bc92 100644 --- a/java/src/org/openqa/selenium/events/zeromq/UnboundZmqEventBus.java +++ b/java/src/org/openqa/selenium/events/zeromq/UnboundZmqEventBus.java @@ -72,9 +72,8 @@ class UnboundZmqEventBus implements EventBus { private final Queue recentMessages = EvictingQueue.create(128); private final String encodedSecret; private final ZMQ.Poller poller; - - private ZMQ.Socket pub; - private ZMQ.Socket sub; + private final ZMQ.Socket pub; + private final ZMQ.Socket sub; UnboundZmqEventBus( ZContext context, @@ -136,20 +135,26 @@ class UnboundZmqEventBus implements EventBus { .build(); // Access to the zmq socket is safe here: no threads. - Failsafe.with(retryPolicy) - .run( - () -> { - sub = context.createSocket(SocketType.SUB); - sub.setIPv6(isSubAddressIPv6(publishConnection)); - ZmqUtils.configureHeartbeat(sub, heartbeatPeriod, "SUB"); - sub.connect(publishConnection); - sub.subscribe(new byte[0]); - - pub = context.createSocket(SocketType.PUB); - pub.setIPv6(isSubAddressIPv6(subscribeConnection)); - ZmqUtils.configureHeartbeat(pub, heartbeatPeriod, "PUB"); - pub.connect(subscribeConnection); - }); + ZMQ.Socket[] pubSub = + Failsafe.with(retryPolicy) + .get( + () -> { + ZMQ.Socket sub = context.createSocket(SocketType.SUB); + sub.setIPv6(isSubAddressIPv6(publishConnection)); + ZmqUtils.configureHeartbeat(sub, heartbeatPeriod, "SUB"); + sub.connect(publishConnection); + sub.subscribe(new byte[0]); + + ZMQ.Socket pub = context.createSocket(SocketType.PUB); + pub.setIPv6(isSubAddressIPv6(subscribeConnection)); + ZmqUtils.configureHeartbeat(pub, heartbeatPeriod, "PUB"); + pub.connect(subscribeConnection); + + return new ZMQ.Socket[] {pub, sub}; + }); + this.pub = pubSub[0]; + this.sub = pubSub[1]; + // Connections are already established this.poller = context.createPoller(1); this.poller.register(Objects.requireNonNull(sub), ZMQ.Poller.POLLIN); @@ -227,13 +232,8 @@ public void close() { ExecutorServices.shutdownGracefully( "Event Bus Listener Notifier", listenerNotificationExecutor); poller.close(); - - if (sub != null) { - sub.close(); - } - if (pub != null) { - pub.close(); - } + sub.close(); + pub.close(); } private class PollingRunnable implements Runnable { diff --git a/java/src/org/openqa/selenium/events/zeromq/ZeroMqEventBus.java b/java/src/org/openqa/selenium/events/zeromq/ZeroMqEventBus.java index 79502bd733ee6..c6635b35e7ee8 100644 --- a/java/src/org/openqa/selenium/events/zeromq/ZeroMqEventBus.java +++ b/java/src/org/openqa/selenium/events/zeromq/ZeroMqEventBus.java @@ -146,6 +146,7 @@ public static class RejectedEvent { this.data = data; } + @SuppressWarnings("DataFlowIssue") private static RejectedEvent fromJson(JsonInput input) { EventName name = null; Object data = null; diff --git a/java/src/org/openqa/selenium/events/zeromq/package-info.java b/java/src/org/openqa/selenium/events/zeromq/package-info.java new file mode 100644 index 0000000000000..371c20bebf257 --- /dev/null +++ b/java/src/org/openqa/selenium/events/zeromq/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.events.zeromq; + +import org.jspecify.annotations.NullMarked; diff --git a/java/src/org/openqa/selenium/interactions/Actions.java b/java/src/org/openqa/selenium/interactions/Actions.java index 107e0f989b7ec..f658d2f040fea 100644 --- a/java/src/org/openqa/selenium/interactions/Actions.java +++ b/java/src/org/openqa/selenium/interactions/Actions.java @@ -30,7 +30,6 @@ import java.util.Objects; import java.util.Set; import java.util.function.IntConsumer; -import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; @@ -46,7 +45,6 @@ * *

Call {@link #perform()} at the end of the method chain to actually perform the actions. */ -@NullMarked public class Actions { private final WebDriver driver; @@ -57,7 +55,7 @@ public class Actions { private @Nullable PointerInput activePointer; private @Nullable KeyInput activeKeyboard; private @Nullable WheelInput activeWheel; - private Duration actionDuration; + private final Duration actionDuration; public Actions(WebDriver driver) { this(driver, Duration.ofMillis(250)); @@ -155,9 +153,7 @@ public Actions sendKeys(WebElement target, CharSequence... keys) { } private Actions sendKeysInTicks(CharSequence... keys) { - if (keys == null) { - throw new IllegalArgumentException("Keys should be a not null CharSequence"); - } + Require.nonNull("Keys", keys, "should be a not null CharSequence"); for (CharSequence key : keys) { key.codePoints() .forEach( diff --git a/java/src/org/openqa/selenium/interactions/CompositeAction.java b/java/src/org/openqa/selenium/interactions/CompositeAction.java index 7005a460a931c..1b9b47fe94680 100644 --- a/java/src/org/openqa/selenium/interactions/CompositeAction.java +++ b/java/src/org/openqa/selenium/interactions/CompositeAction.java @@ -19,11 +19,9 @@ import java.util.ArrayList; import java.util.List; -import org.jspecify.annotations.NullMarked; import org.openqa.selenium.internal.Require; /** An action for aggregating actions and triggering all of them at the same time. */ -@NullMarked public class CompositeAction implements Action { private final List actionsList = new ArrayList<>(); diff --git a/java/src/org/openqa/selenium/interactions/Coordinates.java b/java/src/org/openqa/selenium/interactions/Coordinates.java index e723cd60a28e1..dc6780d98efa7 100644 --- a/java/src/org/openqa/selenium/interactions/Coordinates.java +++ b/java/src/org/openqa/selenium/interactions/Coordinates.java @@ -17,14 +17,12 @@ package org.openqa.selenium.interactions; -import org.jspecify.annotations.NullMarked; import org.openqa.selenium.Point; /** * Provides coordinates of an element for advanced interactions. Note that some coordinates (such as * screen coordinates) are evaluated lazily since the element may have to be scrolled into view. */ -@NullMarked public interface Coordinates { /** diff --git a/java/src/org/openqa/selenium/interactions/Encodable.java b/java/src/org/openqa/selenium/interactions/Encodable.java index 5e05325cca4b8..50a6ba920f031 100644 --- a/java/src/org/openqa/selenium/interactions/Encodable.java +++ b/java/src/org/openqa/selenium/interactions/Encodable.java @@ -18,14 +18,13 @@ package org.openqa.selenium.interactions; import java.util.Map; -import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; /** * This interface allows a custom {@link Interaction} to be JSON encoded for the W3C wire format. It * should not normally be exposed or used by user-facing APIs. Instead, these should traffic in the * {@link Interaction} interface. */ -@NullMarked public interface Encodable { - Map encode(); + Map encode(); } diff --git a/java/src/org/openqa/selenium/interactions/InputSource.java b/java/src/org/openqa/selenium/interactions/InputSource.java index c7c9060e82c73..a8187d1db422f 100644 --- a/java/src/org/openqa/selenium/interactions/InputSource.java +++ b/java/src/org/openqa/selenium/interactions/InputSource.java @@ -17,13 +17,10 @@ package org.openqa.selenium.interactions; -import org.jspecify.annotations.NullMarked; - /** * Models an input source as defined * and used by the W3C WebDriver spec. */ -@NullMarked public interface InputSource { SourceType getInputType(); diff --git a/java/src/org/openqa/selenium/interactions/Interaction.java b/java/src/org/openqa/selenium/interactions/Interaction.java index c7e6de2d0a630..1ebd70cba6018 100644 --- a/java/src/org/openqa/selenium/interactions/Interaction.java +++ b/java/src/org/openqa/selenium/interactions/Interaction.java @@ -19,13 +19,10 @@ import static java.util.Objects.requireNonNull; -import org.jspecify.annotations.NullMarked; - /** * Used as the basis of {@link Sequence}s for the W3C WebDriver spec Action commands. */ -@NullMarked public abstract class Interaction { private final InputSource source; diff --git a/java/src/org/openqa/selenium/interactions/Interactive.java b/java/src/org/openqa/selenium/interactions/Interactive.java index df6b39feee4f9..c47e0fc1ab4d0 100644 --- a/java/src/org/openqa/selenium/interactions/Interactive.java +++ b/java/src/org/openqa/selenium/interactions/Interactive.java @@ -18,13 +18,11 @@ package org.openqa.selenium.interactions; import java.util.Collection; -import org.jspecify.annotations.NullMarked; /** * Indicates that a class can be used with the W3C WebDriver Actions commands. */ -@NullMarked public interface Interactive { void perform(Collection actions); diff --git a/java/src/org/openqa/selenium/interactions/KeyInput.java b/java/src/org/openqa/selenium/interactions/KeyInput.java index c82c5800951b3..92d58016d0748 100644 --- a/java/src/org/openqa/selenium/interactions/KeyInput.java +++ b/java/src/org/openqa/selenium/interactions/KeyInput.java @@ -21,13 +21,11 @@ import java.util.Map; import java.util.Optional; import java.util.UUID; -import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; /** * Models a key input source. */ -@NullMarked public class KeyInput implements InputSource, Encodable { private final String name; @@ -55,8 +53,8 @@ public Interaction createKeyUp(int codePoint) { } @Override - public Map encode() { - Map toReturn = new HashMap<>(); + public Map encode() { + Map toReturn = new HashMap<>(); toReturn.put("type", getInputType().getType()); toReturn.put("id", name); diff --git a/java/src/org/openqa/selenium/interactions/Locatable.java b/java/src/org/openqa/selenium/interactions/Locatable.java index e0360b4e1fa1a..de31c0a14c50e 100644 --- a/java/src/org/openqa/selenium/interactions/Locatable.java +++ b/java/src/org/openqa/selenium/interactions/Locatable.java @@ -17,9 +17,6 @@ package org.openqa.selenium.interactions; -import org.jspecify.annotations.NullMarked; - -@NullMarked public interface Locatable { Coordinates getCoordinates(); } diff --git a/java/src/org/openqa/selenium/interactions/MoveTargetOutOfBoundsException.java b/java/src/org/openqa/selenium/interactions/MoveTargetOutOfBoundsException.java index 36e44703a1f71..27c17d6f4fcb4 100644 --- a/java/src/org/openqa/selenium/interactions/MoveTargetOutOfBoundsException.java +++ b/java/src/org/openqa/selenium/interactions/MoveTargetOutOfBoundsException.java @@ -17,7 +17,6 @@ package org.openqa.selenium.interactions; -import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; import org.openqa.selenium.WebDriverException; @@ -25,7 +24,6 @@ * Indicates that the target provided to the actions move() method is invalid - outside of the size * of the window. */ -@NullMarked public class MoveTargetOutOfBoundsException extends WebDriverException { public MoveTargetOutOfBoundsException(@Nullable String message) { super(message); diff --git a/java/src/org/openqa/selenium/interactions/Pause.java b/java/src/org/openqa/selenium/interactions/Pause.java index e9b7aeec35eba..12d5012cb62c6 100644 --- a/java/src/org/openqa/selenium/interactions/Pause.java +++ b/java/src/org/openqa/selenium/interactions/Pause.java @@ -22,10 +22,8 @@ import java.time.Duration; import java.util.HashMap; import java.util.Map; -import org.jspecify.annotations.NullMarked; /** Indicates that a given {@link InputSource} should pause for a given duration. */ -@NullMarked public class Pause extends Interaction implements Encodable { private final Duration duration; diff --git a/java/src/org/openqa/selenium/interactions/PointerInput.java b/java/src/org/openqa/selenium/interactions/PointerInput.java index d2343e352290e..f756565ccbc9a 100644 --- a/java/src/org/openqa/selenium/interactions/PointerInput.java +++ b/java/src/org/openqa/selenium/interactions/PointerInput.java @@ -24,7 +24,6 @@ import java.util.Map; import java.util.Optional; import java.util.UUID; -import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; import org.openqa.selenium.Point; import org.openqa.selenium.WebElement; @@ -35,7 +34,6 @@ * Models a pointer input * source. */ -@NullMarked public class PointerInput implements InputSource, Encodable { private final Kind kind; @@ -57,8 +55,8 @@ public SourceType getInputType() { } @Override - public Map encode() { - Map toReturn = new HashMap<>(); + public Map encode() { + Map toReturn = new HashMap<>(); toReturn.put("type", getInputType().getType()); toReturn.put("id", name); diff --git a/java/src/org/openqa/selenium/interactions/Sequence.java b/java/src/org/openqa/selenium/interactions/Sequence.java index 61db21eb8b1cb..c9f37756bafa6 100644 --- a/java/src/org/openqa/selenium/interactions/Sequence.java +++ b/java/src/org/openqa/selenium/interactions/Sequence.java @@ -22,7 +22,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; /** * A sequence of action objects for a given {@link InputSource} for use with the W3C actions = new LinkedList<>(); @@ -66,12 +65,12 @@ public Sequence addAction(Interaction action) { } @Override - public Map encode() { - Map toReturn = new HashMap<>(((Encodable) device).encode()); + public Map encode() { + Map toReturn = new HashMap<>(((Encodable) device).encode()); - List> encodedActions = new LinkedList<>(); + List> encodedActions = new LinkedList<>(); for (Encodable action : actions) { - Map encodedAction = new HashMap<>(action.encode()); + Map encodedAction = new HashMap<>(action.encode()); encodedActions.add(encodedAction); } toReturn.put("actions", encodedActions); @@ -79,7 +78,7 @@ public Map encode() { return toReturn; } - public Map toJson() { + public Map toJson() { return encode(); } diff --git a/java/src/org/openqa/selenium/interactions/SourceType.java b/java/src/org/openqa/selenium/interactions/SourceType.java index d69d12db1d42c..ee5f977957bf8 100644 --- a/java/src/org/openqa/selenium/interactions/SourceType.java +++ b/java/src/org/openqa/selenium/interactions/SourceType.java @@ -17,11 +17,9 @@ package org.openqa.selenium.interactions; -import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; /** One of the allowing types for an {@link InputSource}. */ -@NullMarked public enum SourceType { KEY("key"), NONE(null), diff --git a/java/src/org/openqa/selenium/interactions/WheelInput.java b/java/src/org/openqa/selenium/interactions/WheelInput.java index ae0e4dc273067..f5936f2fc8815 100644 --- a/java/src/org/openqa/selenium/interactions/WheelInput.java +++ b/java/src/org/openqa/selenium/interactions/WheelInput.java @@ -24,7 +24,6 @@ import java.util.Map; import java.util.Optional; import java.util.UUID; -import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; import org.openqa.selenium.Point; import org.openqa.selenium.WebElement; @@ -35,7 +34,6 @@ * Models a wheel input * source. */ -@NullMarked public class WheelInput implements InputSource, Encodable { private final String name; @@ -65,8 +63,8 @@ public Interaction createScroll( } @Override - public Map encode() { - Map toReturn = new HashMap<>(); + public Map encode() { + Map toReturn = new HashMap<>(); toReturn.put("type", getInputType().getType()); toReturn.put("id", this.name); diff --git a/java/src/org/openqa/selenium/interactions/package-info.java b/java/src/org/openqa/selenium/interactions/package-info.java new file mode 100644 index 0000000000000..652abe73942f9 --- /dev/null +++ b/java/src/org/openqa/selenium/interactions/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.interactions; + +import org.jspecify.annotations.NullMarked; diff --git a/java/src/org/openqa/selenium/logging/CompositeLocalLogs.java b/java/src/org/openqa/selenium/logging/CompositeLocalLogs.java index d1bbc03651d6e..0bbb1168fe85a 100644 --- a/java/src/org/openqa/selenium/logging/CompositeLocalLogs.java +++ b/java/src/org/openqa/selenium/logging/CompositeLocalLogs.java @@ -19,6 +19,7 @@ import java.util.Set; import java.util.TreeSet; +import org.jspecify.annotations.NullMarked; /** * LocalLogs implementation that holds two other local logs. NOTE: The two local logs are not equal. @@ -42,6 +43,7 @@ protected CompositeLocalLogs(LocalLogs predefinedTypeLogger, LocalLogs allTypesL } @Override + @NullMarked public LogEntries get(String logType) { if (predefinedTypeLogger.getAvailableLogTypes().contains(logType)) { return predefinedTypeLogger.get(logType); diff --git a/java/src/org/openqa/selenium/logging/HandlerBasedLocalLogs.java b/java/src/org/openqa/selenium/logging/HandlerBasedLocalLogs.java index 953962d94b47d..029bbfe6b5a99 100644 --- a/java/src/org/openqa/selenium/logging/HandlerBasedLocalLogs.java +++ b/java/src/org/openqa/selenium/logging/HandlerBasedLocalLogs.java @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Set; +import org.jspecify.annotations.NullMarked; /** * LocalLogs instance that extracts entries from a logging handler. @@ -39,6 +40,7 @@ protected HandlerBasedLocalLogs(LoggingHandler loggingHandler, Set logTy } @Override + @NullMarked public LogEntries get(String logType) { if (LogType.CLIENT.equals(logType) && logTypesToInclude.contains(logType)) { Collection entries = loggingHandler.getRecords(); diff --git a/java/src/org/openqa/selenium/logging/LocalLogs.java b/java/src/org/openqa/selenium/logging/LocalLogs.java index 0304e4b24407a..1ccfaa3e25cc1 100644 --- a/java/src/org/openqa/selenium/logging/LocalLogs.java +++ b/java/src/org/openqa/selenium/logging/LocalLogs.java @@ -19,6 +19,7 @@ import java.util.Collections; import java.util.Set; +import org.jspecify.annotations.NullMarked; /** * Stores and retrieves logs in-process (i.e. without any RPCs). @@ -32,6 +33,7 @@ public abstract class LocalLogs implements Logs { private static final LocalLogs NULL_LOGGER = new LocalLogs() { @Override + @NullMarked public LogEntries get(String logType) { return new LogEntries(Collections.emptyList()); } @@ -79,6 +81,7 @@ public static LocalLogs getCombinedLogsHolder( protected LocalLogs() {} @Override + @NullMarked public abstract LogEntries get(String logType); public abstract void addEntry(String logType, LogEntry entry); diff --git a/java/src/org/openqa/selenium/logging/SessionLogs.java b/java/src/org/openqa/selenium/logging/SessionLogs.java index 47fa21188953c..6b65e31374219 100644 --- a/java/src/org/openqa/selenium/logging/SessionLogs.java +++ b/java/src/org/openqa/selenium/logging/SessionLogs.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Set; import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; import org.openqa.selenium.Beta; import org.openqa.selenium.internal.Require; @@ -44,7 +45,7 @@ public SessionLogs() { this.logTypeToEntriesMap = new HashMap<>(); } - public LogEntries getLogs(String logType) { + public LogEntries getLogs(@Nullable String logType) { if (logType == null || !logTypeToEntriesMap.containsKey(logType)) { return new LogEntries(Collections.emptyList()); } diff --git a/java/src/org/openqa/selenium/logging/StoringLocalLogs.java b/java/src/org/openqa/selenium/logging/StoringLocalLogs.java index f9a9fafe4e404..45dfa9535f547 100644 --- a/java/src/org/openqa/selenium/logging/StoringLocalLogs.java +++ b/java/src/org/openqa/selenium/logging/StoringLocalLogs.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.NullMarked; /** * LocalLogs instance that has its own storage. This should be used for explicit storing of logs, @@ -40,6 +41,7 @@ public StoringLocalLogs(Set logTypesToInclude) { } @Override + @NullMarked public LogEntries get(String logType) { return new LogEntries(getLocalLogs(logType)); } diff --git a/java/src/org/openqa/selenium/logging/package-info.java b/java/src/org/openqa/selenium/logging/package-info.java new file mode 100644 index 0000000000000..bb0b5d16cb365 --- /dev/null +++ b/java/src/org/openqa/selenium/logging/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.logging; + +import org.jspecify.annotations.NullMarked; diff --git a/java/src/org/openqa/selenium/logging/profiler/package-info.java b/java/src/org/openqa/selenium/logging/profiler/package-info.java new file mode 100644 index 0000000000000..3a75c30f614cf --- /dev/null +++ b/java/src/org/openqa/selenium/logging/profiler/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.logging.profiler; + +import org.jspecify.annotations.NullMarked; diff --git a/java/src/org/openqa/selenium/remote/AddHasLogEvents.java b/java/src/org/openqa/selenium/remote/AddHasLogEvents.java index e274ef74d1bf1..711ea2d8488ce 100644 --- a/java/src/org/openqa/selenium/remote/AddHasLogEvents.java +++ b/java/src/org/openqa/selenium/remote/AddHasLogEvents.java @@ -22,6 +22,7 @@ import static org.openqa.selenium.remote.Browser.OPERA; import java.util.function.Predicate; +import org.jspecify.annotations.NullMarked; import org.openqa.selenium.Capabilities; import org.openqa.selenium.WebDriver; import org.openqa.selenium.devtools.HasDevTools; @@ -47,6 +48,7 @@ public Class getDescribedInterface() { public HasLogEvents getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) { return new HasLogEvents() { @Override + @NullMarked public void onLogEvent(EventType kind) { if (((RemoteExecuteMethod) executeMethod).getWrappedDriver() instanceof HasDevTools) { WebDriver driver = ((RemoteExecuteMethod) executeMethod).getWrappedDriver(); diff --git a/java/src/org/openqa/selenium/remote/RemoteLogs.java b/java/src/org/openqa/selenium/remote/RemoteLogs.java index 267558e892e14..22ff5679eaf55 100644 --- a/java/src/org/openqa/selenium/remote/RemoteLogs.java +++ b/java/src/org/openqa/selenium/remote/RemoteLogs.java @@ -26,6 +26,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; +import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; import org.openqa.selenium.Beta; import org.openqa.selenium.UnsupportedCommandException; @@ -67,6 +68,7 @@ public RemoteLogs(ExecuteMethod executeMethod, LocalLogs localLogs) { } @Override + @NullMarked @SuppressWarnings("deprecation") public LogEntries get(String logType) { if (LogType.CLIENT.equals(logType)) { diff --git a/java/src/org/openqa/selenium/remote/RemoteWebDriver.java b/java/src/org/openqa/selenium/remote/RemoteWebDriver.java index 0ed6e13909865..96751313b89f3 100644 --- a/java/src/org/openqa/selenium/remote/RemoteWebDriver.java +++ b/java/src/org/openqa/selenium/remote/RemoteWebDriver.java @@ -47,6 +47,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; import org.openqa.selenium.AcceptedW3CCapabilityKeys; import org.openqa.selenium.Alert; @@ -696,6 +697,7 @@ protected ExecuteMethod getExecuteMethod() { } @Override + @NullMarked public void perform(Collection actions) { execute(DriverCommand.ACTIONS(actions)); }