Skip to content

refactor: Migrate from JSR 305 to JSpecify #2281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ dependencies {
}
implementation 'com.google.code.gson:gson:2.12.1'
implementation "org.slf4j:slf4j-api:${slf4jVersion}"
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation 'org.jspecify:jspecify:1.0.0'
}

dependencyCheck {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

import io.appium.java_client.internal.filters.AppiumIdempotencyFilter;
import io.appium.java_client.internal.filters.AppiumUserAgentFilter;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.Credentials;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.http.ClientConfig;
import org.openqa.selenium.remote.http.Filter;

import javax.annotation.Nullable;
import javax.net.ssl.SSLContext;
import java.net.Proxy;
import java.net.URI;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import lombok.Getter;
import org.jspecify.annotations.NonNull;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.OutputType;
Expand All @@ -47,7 +48,6 @@
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.http.HttpMethod;

import javax.annotation.Nonnull;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
Expand Down Expand Up @@ -275,7 +275,7 @@ public Optional<BiDi> maybeGetBiDi() {
}

@Override
@Nonnull
@NonNull
public BiDi getBiDi() {
var webSocketUrl = ((BaseOptions<?>) this.capabilities).getWebSocketUrl().orElseThrow(
() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package io.appium.java_client;

import org.jspecify.annotations.Nullable;
import org.openqa.selenium.remote.Response;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.Map;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/appium/java_client/ComparesImages.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;
import io.appium.java_client.imagecomparison.SimilarityMatchingOptions;
import io.appium.java_client.imagecomparison.SimilarityMatchingResult;
import org.jspecify.annotations.Nullable;

import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package io.appium.java_client;

import org.jspecify.annotations.Nullable;
import org.openqa.selenium.remote.Response;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import io.appium.java_client.driverscripts.ScriptOptions;
import io.appium.java_client.driverscripts.ScriptValue;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.remote.Response;

import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import io.appium.java_client.appmanagement.BaseOptions;
import io.appium.java_client.appmanagement.BaseRemoveApplicationOptions;
import io.appium.java_client.appmanagement.BaseTerminateApplicationOptions;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.InvalidArgumentException;
import org.openqa.selenium.UnsupportedCommandException;

import javax.annotation.Nullable;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/appium/java_client/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

import javax.annotation.Nullable;
import org.jspecify.annotations.Nullable;

/**
* Represents the physical location.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/appium/java_client/MobileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import io.appium.java_client.imagecomparison.ComparisonMode;
import io.appium.java_client.screenrecording.BaseStartScreenRecordingOptions;
import io.appium.java_client.screenrecording.BaseStopScreenRecordingOptions;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.remote.CommandInfo;
import org.openqa.selenium.remote.http.HttpMethod;

import javax.annotation.Nullable;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
import io.appium.java_client.CanRememberExtensionPresence;
import io.appium.java_client.CommandExecutionHelper;
import io.appium.java_client.ExecutesMethod;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.UnsupportedCommandException;

import javax.annotation.Nullable;

import java.util.Map;

import static io.appium.java_client.MobileCommand.CURRENT_ACTIVITY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package io.appium.java_client.internal;

import org.jspecify.annotations.Nullable;
import org.openqa.selenium.Capabilities;

import javax.annotation.Nullable;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
package io.appium.java_client.internal.filters;

import io.appium.java_client.internal.Config;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.remote.http.AddSeleniumUserAgent;
import org.openqa.selenium.remote.http.Filter;
import org.openqa.selenium.remote.http.HttpHandler;
import org.openqa.selenium.remote.http.HttpHeader;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Manage Appium Client configurations.
*/
Expand All @@ -41,7 +40,7 @@ public class AppiumUserAgentFilter implements Filter {
*/
public static final String USER_AGENT = buildUserAgentHeaderValue(AddSeleniumUserAgent.USER_AGENT);

private static String buildUserAgentHeaderValue(@Nonnull String previousUA) {
private static String buildUserAgentHeaderValue(@NonNull String previousUA) {
return String.format("%s%s (%s)",
USER_AGENT_PREFIX, Config.main().getValue(VERSION_KEY, String.class), previousUA);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import io.appium.java_client.pagefactory.bys.builder.AppiumByBuilder;
import io.appium.java_client.pagefactory.locator.CacheableElementLocatorFactory;
import io.appium.java_client.pagefactory.locator.CacheableLocator;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.SearchContext;

import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import io.appium.java_client.internal.CapabilityHelpers;
import io.appium.java_client.pagefactory.bys.ContentType;
import io.appium.java_client.pagefactory.locator.CacheableLocator;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.HasCapabilities;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebDriver;
Expand All @@ -30,8 +32,6 @@
import org.openqa.selenium.support.pagefactory.ElementLocatorFactory;
import org.openqa.selenium.support.pagefactory.FieldDecorator;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -123,7 +123,7 @@ contextReference, duration, new WidgetByBuilder(platform, automation)
);
}

@Nonnull
@NonNull
private static WeakReference<WebDriver> requireWebDriverReference(SearchContext searchContext) {
var wd = unpackObjectFromSearchContext(
checkNotNull(searchContext, "The provided search context cannot be null"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import io.appium.java_client.pagefactory.bys.ContentType;
import io.appium.java_client.pagefactory.interceptors.InterceptorOfASingleElement;
import io.appium.java_client.pagefactory.locator.CacheableLocator;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.PageFactory;

import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
Expand All @@ -48,11 +48,9 @@ public class WidgetInterceptor extends InterceptorOfASingleElement {
* Proxy interceptor class for widgets.
*/
public WidgetInterceptor(
@Nullable
CacheableLocator locator,
@Nullable CacheableLocator locator,
WeakReference<WebDriver> driverReference,
@Nullable
WeakReference<WebElement> cachedElementReference,
@Nullable WeakReference<WebElement> cachedElementReference,
Map<ContentType, Constructor<? extends Widget>> instantiationMap,
Duration duration
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import io.appium.java_client.pagefactory.bys.ContentType;
import io.appium.java_client.pagefactory.interceptors.InterceptorOfAListOfElements;
import io.appium.java_client.pagefactory.locator.CacheableLocator;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -50,8 +50,7 @@ public class WidgetListInterceptor extends InterceptorOfAListOfElements {
* Proxy interceptor class for lists of widgets.
*/
public WidgetListInterceptor(
@Nullable
CacheableLocator locator,
@Nullable CacheableLocator locator,
WeakReference<WebDriver> driver,
Map<ContentType, Constructor<? extends Widget>> instantiationMap,
Class<? extends Widget> declaredType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
package io.appium.java_client.pagefactory.bys;

import lombok.EqualsAndHashCode;
import org.jspecify.annotations.NonNull;
import org.openqa.selenium.By;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebElement;

import javax.annotation.Nonnull;
import java.util.List;
import java.util.Map;

Expand All @@ -43,7 +43,7 @@ public ContentMappedBy(Map<ContentType, By> map) {
* @param type required content type {@link ContentType}
* @return self-reference.
*/
public By useContent(@Nonnull ContentType type) {
public By useContent(@NonNull ContentType type) {
requireNonNull(type);
currentContent = type;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package io.appium.java_client.pagefactory.bys.builder;

import org.jspecify.annotations.Nullable;
import org.openqa.selenium.By;
import org.openqa.selenium.support.pagefactory.AbstractAnnotations;
import org.openqa.selenium.support.pagefactory.ByAll;

import javax.annotation.Nullable;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package io.appium.java_client.pagefactory.interceptors;

import io.appium.java_client.proxy.MethodCallListener;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.pagefactory.ElementLocator;

import javax.annotation.Nullable;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
package io.appium.java_client.pagefactory.interceptors;

import io.appium.java_client.proxy.MethodCallListener;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WrapsDriver;
import org.openqa.selenium.remote.RemoteWebElement;
import org.openqa.selenium.support.pagefactory.ElementLocator;

import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.util.Objects;
Expand All @@ -34,8 +34,7 @@ public abstract class InterceptorOfASingleElement implements MethodCallListener
private final WeakReference<WebDriver> driverReference;

public InterceptorOfASingleElement(
@Nullable
ElementLocator locator,
@Nullable ElementLocator locator,
WeakReference<WebDriver> driverReference
) {
this.locator = locator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@

import io.appium.java_client.HasBrowserCheck;
import io.appium.java_client.pagefactory.bys.ContentType;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.ContextAware;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WrapsDriver;
import org.openqa.selenium.WrapsElement;

import javax.annotation.Nullable;

import java.util.Optional;

import static io.appium.java_client.HasBrowserCheck.NATIVE_CONTEXT;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/appium/java_client/proxy/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatchers;
import org.jspecify.annotations.Nullable;

import javax.annotation.Nullable;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import io.appium.java_client.AppiumClientConfig;
import io.appium.java_client.internal.ReflectionHelpers;
import lombok.Getter;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.SessionNotCreatedException;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.Command;
Expand All @@ -34,12 +36,11 @@
import org.openqa.selenium.remote.ResponseCodec;
import org.openqa.selenium.remote.codec.w3c.W3CHttpCommandCodec;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.http.HttpClient.Factory;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;
import org.openqa.selenium.remote.service.DriverService;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.net.ConnectException;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -69,10 +70,10 @@ public class AppiumCommandExecutor extends HttpCommandExecutor {
* @param appiumClientConfig take a look at {@link AppiumClientConfig}
*/
public AppiumCommandExecutor(
@Nonnull Map<String, CommandInfo> additionalCommands,
@NonNull Map<String, CommandInfo> additionalCommands,
@Nullable DriverService service,
@Nullable HttpClient.Factory httpClientFactory,
@Nonnull AppiumClientConfig appiumClientConfig) {
@Nullable Factory httpClientFactory,
@NonNull AppiumClientConfig appiumClientConfig) {
super(additionalCommands,
appiumClientConfig,
ofNullable(httpClientFactory).orElseGet(AppiumCommandExecutor::getDefaultClientFactory)
Expand Down
Loading