From 0d366192e311a1cc3deb576abeb054fe903d954b Mon Sep 17 00:00:00 2001 From: Alex Popov Date: Wed, 9 Jul 2025 02:37:58 +0700 Subject: [PATCH] added annotations and applied format.sh exception classes --- .../org/openqa/selenium/NoSuchSessionException.java | 8 ++++++-- .../org/openqa/selenium/ScriptTimeoutException.java | 10 +++++++--- .../openqa/selenium/SessionNotCreatedException.java | 8 ++++++-- java/src/org/openqa/selenium/TimeoutException.java | 10 +++++++--- .../org/openqa/selenium/UnhandledAlertException.java | 10 +++++++--- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/java/src/org/openqa/selenium/NoSuchSessionException.java b/java/src/org/openqa/selenium/NoSuchSessionException.java index 45dfe71c252b7..3c705afba3d37 100644 --- a/java/src/org/openqa/selenium/NoSuchSessionException.java +++ b/java/src/org/openqa/selenium/NoSuchSessionException.java @@ -17,16 +17,20 @@ package org.openqa.selenium; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; + /** Thrown by any command being called after {@link WebDriver#quit() WebDriver.quit()}. */ +@NullMarked public class NoSuchSessionException extends WebDriverException { public NoSuchSessionException() {} - public NoSuchSessionException(String reason) { + public NoSuchSessionException(@Nullable String reason) { super(reason); } - public NoSuchSessionException(String reason, Throwable cause) { + public NoSuchSessionException(@Nullable String reason, @Nullable Throwable cause) { super(reason, cause); } } diff --git a/java/src/org/openqa/selenium/ScriptTimeoutException.java b/java/src/org/openqa/selenium/ScriptTimeoutException.java index 55e627a08f402..5fac22842a5a7 100644 --- a/java/src/org/openqa/selenium/ScriptTimeoutException.java +++ b/java/src/org/openqa/selenium/ScriptTimeoutException.java @@ -17,20 +17,24 @@ package org.openqa.selenium; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; + /** Thrown when an async execute script command does not complete in enough time. */ +@NullMarked public class ScriptTimeoutException extends WebDriverException { public ScriptTimeoutException() {} - public ScriptTimeoutException(String message) { + public ScriptTimeoutException(@Nullable String message) { super(message); } - public ScriptTimeoutException(Throwable cause) { + public ScriptTimeoutException(@Nullable Throwable cause) { super(cause); } - public ScriptTimeoutException(String message, Throwable cause) { + public ScriptTimeoutException(@Nullable String message, @Nullable Throwable cause) { super(message, cause); } } diff --git a/java/src/org/openqa/selenium/SessionNotCreatedException.java b/java/src/org/openqa/selenium/SessionNotCreatedException.java index 30bb9d6c2ab21..20b8511f7c4c6 100644 --- a/java/src/org/openqa/selenium/SessionNotCreatedException.java +++ b/java/src/org/openqa/selenium/SessionNotCreatedException.java @@ -17,16 +17,20 @@ package org.openqa.selenium; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; + /** Indicates that a session could not be created. */ +@NullMarked public class SessionNotCreatedException extends WebDriverException { - public SessionNotCreatedException(String msg) { + public SessionNotCreatedException(@Nullable String msg) { super( "Could not start a new session. " + msg + (msg != null && msg.contains("Host info") ? "" : " \n" + getHostInformation())); } - public SessionNotCreatedException(String msg, Throwable cause) { + public SessionNotCreatedException(@Nullable String msg, @Nullable Throwable cause) { super( "Could not start a new session. " + msg diff --git a/java/src/org/openqa/selenium/TimeoutException.java b/java/src/org/openqa/selenium/TimeoutException.java index b7b24608230ce..65d3b3300fa86 100644 --- a/java/src/org/openqa/selenium/TimeoutException.java +++ b/java/src/org/openqa/selenium/TimeoutException.java @@ -17,20 +17,24 @@ package org.openqa.selenium; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; + /** Thrown when a command does not complete in enough time. */ +@NullMarked public class TimeoutException extends WebDriverException { public TimeoutException() {} - public TimeoutException(String message) { + public TimeoutException(@Nullable String message) { super(message); } - public TimeoutException(Throwable cause) { + public TimeoutException(@Nullable Throwable cause) { super(cause); } - public TimeoutException(String message, Throwable cause) { + public TimeoutException(@Nullable String message, @Nullable Throwable cause) { super(message, cause); } } diff --git a/java/src/org/openqa/selenium/UnhandledAlertException.java b/java/src/org/openqa/selenium/UnhandledAlertException.java index 46c96ba5735fb..77cbc1e4936bf 100644 --- a/java/src/org/openqa/selenium/UnhandledAlertException.java +++ b/java/src/org/openqa/selenium/UnhandledAlertException.java @@ -20,16 +20,19 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; +@NullMarked public class UnhandledAlertException extends WebDriverException { - private final String alertText; + @Nullable private final String alertText; - public UnhandledAlertException(String message) { + public UnhandledAlertException(@Nullable String message) { this(message, null); } - public UnhandledAlertException(String message, String alertText) { + public UnhandledAlertException(@Nullable String message, @Nullable String alertText) { super(message + ": " + alertText); this.alertText = alertText; } @@ -37,6 +40,7 @@ public UnhandledAlertException(String message, String alertText) { /** * @return the text of the unhandled alert. */ + @Nullable public String getAlertText() { return alertText; }