Skip to content

Commit

Permalink
Code cleanup (#12934)
Browse files Browse the repository at this point in the history
* fix IDEA warning "Non-final field in 'enum'"

* fix IDEA warning "Field can be final"

* Format files

---------

Co-authored-by: Diego Molina <[email protected]>
Co-authored-by: Diego Molina <[email protected]>
  • Loading branch information
3 people authored Jan 9, 2024
1 parent f7fd6d3 commit 7ddd002
Show file tree
Hide file tree
Showing 33 changed files with 70 additions and 67 deletions.
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/PageLoadStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum PageLoadStrategy {
EAGER("eager"),
NORMAL("normal");

private String text;
private final String text;

PageLoadStrategy(String text) {
this.text = text;
Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/UnexpectedAlertBehaviour.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum UnexpectedAlertBehaviour {
DISMISS_AND_NOTIFY("dismiss and notify"),
IGNORE("ignore");

private String text;
private final String text;

UnexpectedAlertBehaviour(String text) {
this.text = text;
Expand Down
32 changes: 16 additions & 16 deletions java/src/org/openqa/selenium/devtools/CdpClientGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
}

private static class Model {
private List<Domain> domains = new ArrayList<>();
private String basePackage;
private final List<Domain> domains = new ArrayList<>();
private final String basePackage;

public Model(String basePackage) {
this.basePackage = basePackage;
Expand Down Expand Up @@ -149,7 +149,7 @@ public void dumpTo(Path target) {
}

private static class Parser<T extends BaseSpec> {
private Map<String, BiConsumer<T, Object>> processors;
private final Map<String, BiConsumer<T, Object>> processors;

public Parser(Map<String, BiConsumer<T, Object>> processors) {
this.processors = processors;
Expand Down Expand Up @@ -247,11 +247,11 @@ public TypedSpecParser(boolean inline, Map<String, BiConsumer<T, Object>> extraP
}

private static class Domain extends BaseSpec {
private Model model;
private final Model model;

private List<TypeSpec> types = new ArrayList<>();
private List<CommandSpec> commands = new ArrayList<>();
private List<EventSpec> events = new ArrayList<>();
private final List<TypeSpec> types = new ArrayList<>();
private final List<CommandSpec> commands = new ArrayList<>();
private final List<EventSpec> events = new ArrayList<>();

public Domain(Model model) {
this.model = model;
Expand Down Expand Up @@ -794,8 +794,8 @@ public String getMapper() {
}

private static class SimpleType implements IType {
private String name;
private String type;
private final String name;
private final String type;

public SimpleType(String name, String type) {
this.name = name;
Expand Down Expand Up @@ -1075,9 +1075,9 @@ public String getJavaType() {

private static class ObjectType implements IType {

private TypedSpec parent;
private String name;
private List<VariableSpec> properties;
private final TypedSpec parent;
private final String name;
private final List<VariableSpec> properties;

public ObjectType(TypedSpec parent, String name, List<VariableSpec> properties) {
this.parent = parent;
Expand Down Expand Up @@ -1225,7 +1225,7 @@ public String getMapper() {

private static class ArrayType implements IType {
private IType itemType;
private String name;
private final String name;

public ArrayType(String name) {
this.name = name;
Expand Down Expand Up @@ -1310,9 +1310,9 @@ public void parse(Domain domain, Map<String, Object> json) {
}

private static class RefType implements IType {
private String name;
private Domain domain;
private String type;
private final String name;
private final Domain domain;
private final String type;

public RefType(String name, Domain domain, String type) {
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

public class NoOpDomains implements Domains {

private static BuildInfo INFO = new BuildInfo();
private static final BuildInfo INFO = new BuildInfo();

private static final String WARNING =
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class UnboundZmqEventBus implements EventBus {
private final Map<EventName, List<Consumer<Event>>> listeners = new ConcurrentHashMap<>();
private final Queue<UUID> recentMessages = EvictingQueue.create(128);
private final String encodedSecret;
private ZMQ.Poller poller;
private final ZMQ.Poller poller;

private ZMQ.Socket pub;
private ZMQ.Socket sub;
Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/firefox/FirefoxBinary.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public enum Channel {
DEV("dev"),
NIGHTLY("nightly");

private String name;
private final String name;

Channel(String name) {
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum FirefoxCommandContext {
CONTENT("content"),
CHROME("chrome");

private String text;
private final String text;

FirefoxCommandContext(String text) {
this.text = text;
Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/firefox/FirefoxDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class FirefoxDriver extends RemoteWebDriver
private final Optional<URI> biDiUri;
private Connection connection;
private DevTools devTools;
private Optional<BiDi> biDi;
private final Optional<BiDi> biDi;

/**
* Creates a new FirefoxDriver using the {@link GeckoDriverService#createDefaultService)} server
Expand Down
4 changes: 2 additions & 2 deletions java/src/org/openqa/selenium/firefox/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class Preferences {
private static final Pattern PREFERENCE_PATTERN =
Pattern.compile("user_pref\\(\"([^\"]+)\", (\"?.+?\"?)\\);");

private Map<String, Object> immutablePrefs = new HashMap<>();
private Map<String, Object> allPrefs = new HashMap<>();
private final Map<String, Object> immutablePrefs = new HashMap<>();
private final Map<String, Object> allPrefs = new HashMap<>();

public Preferences() {}

Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/firefox/ProfilesIni.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.openqa.selenium.io.TemporaryFilesystem;

public class ProfilesIni {
private Map<String, File> profiles;
private final Map<String, File> profiles;

public ProfilesIni() {
File appData = locateAppDataDirectory(Platform.getCurrent());
Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/ie/ElementScrollBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum ElementScrollBehavior {
BOTTOM(1),
;

private int value;
private final int value;

ElementScrollBehavior(int value) {
this.value = value;
Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/json/JsonInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class JsonInput implements Closeable {

private final Reader source;
// FIXME: This flag is never set
private volatile boolean readPerformed = false;
private final boolean readPerformed = false;
private JsonTypeCoercer coercer;
private PropertySetting setter;
private final Input input;
Expand Down
4 changes: 2 additions & 2 deletions java/src/org/openqa/selenium/logging/CompositeLocalLogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
* LocalLogs instance.
*/
class CompositeLocalLogs extends LocalLogs {
private LocalLogs predefinedTypeLogger;
private LocalLogs allTypesLogger;
private final LocalLogs predefinedTypeLogger;
private final LocalLogs allTypesLogger;

protected CompositeLocalLogs(LocalLogs predefinedTypeLogger, LocalLogs allTypesLogger) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ private enum Continuation {
private static final Logger LOG = Logger.getLogger(MessageInboundConverter.class.getName());

private Continuation next;
private StringBuilder builder;
private ByteArrayOutputStream buffer;
private final StringBuilder builder;
private final ByteArrayOutputStream buffer;

public MessageInboundConverter() {
next = Continuation.None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@

class SeleniumHttpInitializer extends ChannelInitializer<SocketChannel> {

private static AttributeKey<Consumer<Message>> KEY = AttributeKey.newInstance("se-ws-handler");
private HttpHandler seleniumHandler;
private static final AttributeKey<Consumer<Message>> KEY =
AttributeKey.newInstance("se-ws-handler");
private final HttpHandler seleniumHandler;
private final BiFunction<String, Consumer<Message>, Optional<Consumer<Message>>> webSocketHandler;
private SslContext sslCtx;
private final SslContext sslCtx;
private final boolean allowCors;

SeleniumHttpInitializer(
Expand Down
3 changes: 2 additions & 1 deletion java/src/org/openqa/selenium/os/OsProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class OsProcess {
private final Executor executor = new DaemonExecutor();

private volatile OutputStream drainTo;
private SeleniumWatchDog executeWatchdog = new SeleniumWatchDog(ExecuteWatchdog.INFINITE_TIMEOUT);
private final SeleniumWatchDog executeWatchdog =
new SeleniumWatchDog(ExecuteWatchdog.INFINITE_TIMEOUT);
private PumpStreamHandler streamHandler;

private final org.apache.commons.exec.CommandLine cl;
Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/remote/ErrorHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ErrorHandler {
private static final String UNKNOWN_METHOD = "<anonymous method>";
private static final String UNKNOWN_FILE = null;

private ErrorCodes errorCodes;
private final ErrorCodes errorCodes;

private boolean includeServerErrors;

Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/remote/http/Contents.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private static final class MemoizedSupplier implements Supplier<InputStream> {

private volatile boolean initialized;
private volatile FileBackedOutputStream fos;
private Supplier<InputStream> delegate;
private final Supplier<InputStream> delegate;

private MemoizedSupplier(Supplier<InputStream> delegate) {
this.delegate = delegate;
Expand Down
6 changes: 3 additions & 3 deletions java/src/org/openqa/selenium/support/ByIdOrName.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class ByIdOrName extends By implements Serializable {

private static final long serialVersionUID = 3986638402799576701L;

private By idFinder;
private By nameFinder;
private String idOrName;
private final By idFinder;
private final By nameFinder;
private final String idOrName;

public ByIdOrName(String idOrName) {
this.idOrName = idOrName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ByAll extends By implements Serializable {

private static final long serialVersionUID = 4573668832699497306L;

private By[] bys;
private final By[] bys;

public ByAll(By... bys) {
this.bys = bys;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ByChained extends By implements Serializable {

private static final long serialVersionUID = 1563769051170172451L;

private By[] bys;
private final By[] bys;

public ByChained(By... bys) {
this.bys = bys;
Expand Down
2 changes: 1 addition & 1 deletion java/src/org/openqa/selenium/support/ui/FluentWait.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class FluentWait<T> implements Wait<T> {
private Duration interval = DEFAULT_WAIT_DURATION;
private Supplier<String> messageSupplier = () -> null;

private List<Class<? extends Throwable>> ignoredExceptions = new ArrayList<>();
private final List<Class<? extends Throwable>> ignoredExceptions = new ArrayList<>();

/**
* @param input The input value to pass to the evaluated conditions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import org.openqa.selenium.remote.tracing.Tracer;

class ReverseProxyHandlerTest {
private Tracer tracer = DefaultTestTracer.createTracer();
private HttpClient.Factory factory = HttpClient.Factory.createDefault();
private final Tracer tracer = DefaultTestTracer.createTracer();
private final HttpClient.Factory factory = HttpClient.Factory.createDefault();

@Test
void shouldForwardRequestsToEndPoint()
Expand Down
12 changes: 6 additions & 6 deletions java/test/org/openqa/selenium/json/JsonOutputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ public List<?> getList() {
}

class JsonAware {
private String convertedValue;
private final String convertedValue;

public JsonAware(String convertedValue) {
this.convertedValue = convertedValue;
Expand All @@ -856,7 +856,7 @@ public String toJson() {
}

class MappableJsonAware {
private String convertedValue;
private final String convertedValue;

public MappableJsonAware(String convertedValue) {
this.convertedValue = convertedValue;
Expand All @@ -872,8 +872,8 @@ public Map<String, Object> asMap() {
}

class Mappable1 {
private String key;
private Object value;
private final String key;
private final Object value;

public Mappable1(String key, Object value) {
this.key = key;
Expand All @@ -886,8 +886,8 @@ public Map<String, Object> asMap() {
}

class Mappable2 {
private String key;
private Object value;
private final String key;
private final Object value;

public Mappable2(String key, Object value) {
this.key = key;
Expand Down
4 changes: 2 additions & 2 deletions java/test/org/openqa/selenium/json/JsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ public void setBean(SimpleBean bean) {
}

public static class JsonAware {
private String convertedValue;
private final String convertedValue;

public JsonAware(String convertedValue) {
this.convertedValue = convertedValue;
Expand All @@ -573,7 +573,7 @@ public static JsonAware fromJson(String json) {
}

public static class PrivatelyAware {
private String convertedValue;
private final String convertedValue;

public PrivatelyAware(String convertedValue) {
this.convertedValue = convertedValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public class SimpleHttpServer implements Closeable {

private final Channel channel;

private Map<Map.Entry<HttpMethod, String>, Function<HttpRequest, FullHttpResponse>> endpoints;
private final Map<Map.Entry<HttpMethod, String>, Function<HttpRequest, FullHttpResponse>>
endpoints;

public SimpleHttpServer() throws InterruptedException, URISyntaxException {
this(PortProber.findFreePort());
Expand Down
2 changes: 1 addition & 1 deletion java/test/org/openqa/selenium/remote/ErrorCodecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
@Tag("UnitTests")
public class ErrorCodecTest {

private ErrorCodec errorCodec = ErrorCodec.createDefault();
private final ErrorCodec errorCodec = ErrorCodec.createDefault();

@Test
void encodeW3cSpecExceptions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected void isLoaded() throws Error {

private static class SlowLoading extends SlowLoadableComponent<SlowLoading> {

private int counts;
private final int counts;
private long loopCount;

public SlowLoading(Clock clock, int timeOutInSeconds, int counts) {
Expand Down
2 changes: 1 addition & 1 deletion java/test/org/openqa/selenium/testing/Safely.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static void safelyCall(TearDownFixture... fixtures) {
try {
CompletableFuture.allOf(futures.toArray(new CompletableFuture[] {})).get(2, TimeUnit.MINUTES);
} catch (TimeoutException ex) {
LOG.log(Level.WARNING, "tear down timed out");
LOG.log(Level.WARNING, "tear down timed out: {}", ex.toString());
} catch (Exception ex) {
LOG.log(Level.WARNING, "tear down failed", ex);
}
Expand Down
Loading

0 comments on commit 7ddd002

Please sign in to comment.