Skip to content

Commit 5f3bc8f

Browse files
committed
[java] Fix spotbugs issues
1 parent 088fe35 commit 5f3bc8f

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

java/src/org/openqa/selenium/chromium/ChromiumDriver.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ public void launchApp(String id) {
321321
@Override
322322
public Map<String, Object> executeCdpCommand(String commandName, Map<String, Object> parameters) {
323323
Require.nonNull("Command Name", commandName);
324+
if (this.cdp == null) {
325+
return java.util.Collections.emptyMap();
326+
}
327+
324328
return cdp.executeCdpCommand(commandName, parameters);
325329
}
326330

@@ -358,36 +362,56 @@ public Optional<BiDi> maybeGetBiDi() {
358362

359363
@Override
360364
public List<Map<String, String>> getCastSinks() {
365+
if (this.casting == null) {
366+
return java.util.Collections.emptyList();
367+
}
368+
361369
return casting.getCastSinks();
362370
}
363371

364372
@Override
365373
public String getCastIssueMessage() {
374+
if (this.casting == null) {
375+
return "";
376+
}
377+
366378
return casting.getCastIssueMessage();
367379
}
368380

369381
@Override
370382
public void selectCastSink(String deviceName) {
371383
Require.nonNull("Device Name", deviceName);
372-
casting.selectCastSink(deviceName);
384+
385+
if (this.casting != null) {
386+
casting.selectCastSink(deviceName);
387+
}
373388
}
374389

375390
@Override
376391
public void startDesktopMirroring(String deviceName) {
377392
Require.nonNull("Device Name", deviceName);
378-
casting.startDesktopMirroring(deviceName);
393+
394+
if (this.casting != null) {
395+
casting.startDesktopMirroring(deviceName);
396+
}
379397
}
380398

381399
@Override
382400
public void startTabMirroring(String deviceName) {
383401
Require.nonNull("Device Name", deviceName);
384-
casting.startTabMirroring(deviceName);
402+
403+
if (this.casting != null) {
404+
casting.startTabMirroring(deviceName);
405+
}
385406
}
386407

387408
@Override
388409
public void stopCasting(String deviceName) {
389410
Require.nonNull("Device Name", deviceName);
390-
casting.stopCasting(deviceName);
411+
412+
if (this.casting != null) {
413+
casting.stopCasting(deviceName);
414+
}
391415
}
392416

393417
@Override

java/src/org/openqa/selenium/firefox/ProfilesIni.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ protected File locateAppDataDirectory(Platform os) {
136136
appData =
137137
new File(
138138
MessageFormat.format(
139-
"{0}/Library/Application Support/Firefox", System.getenv("HOME")));
139+
"{0}/Library/Application Support/Firefox", System.getProperty("user.home")));
140140

141141
} else {
142-
appData = new File(MessageFormat.format("{0}/.mozilla/firefox", System.getenv("HOME")));
142+
appData = new File(MessageFormat.format("{0}/.mozilla/firefox", System.getProperty("user.home")));
143143
}
144144

145145
if (!appData.exists()) {

java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -523,17 +523,15 @@ public void close() {
523523
}
524524
}
525525

526-
if (this.client instanceof AutoCloseable) {
527-
AutoCloseable closeable = (AutoCloseable) this.client;
528-
executorService.submit(
529-
() -> {
530-
try {
531-
closeable.close();
532-
} catch (Exception e) {
533-
LOG.log(Level.WARNING, "failed to close the http client: " + closeable, e);
534-
}
535-
});
536-
}
526+
AutoCloseable closeable = (AutoCloseable) this.client;
527+
executorService.submit(
528+
() -> {
529+
try {
530+
closeable.close();
531+
} catch (Exception e) {
532+
LOG.log(Level.WARNING, "failed to close the http client: " + closeable, e);
533+
}
534+
});
537535
this.client = null;
538536
executorService.shutdown();
539537
}

java/src/org/openqa/selenium/remote/tracing/opentelemetry/OpenTelemetryTracer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
public class OpenTelemetryTracer implements org.openqa.selenium.remote.tracing.Tracer {
3232

3333
private static final Logger LOG = Logger.getLogger(OpenTelemetryTracer.class.getName());
34-
private static boolean HTTP_LOGS;
34+
private static volatile boolean HTTP_LOGS;
3535

3636
// We obtain the underlying tracer instance from the singleton instance
3737
// that OpenTelemetry maintains. If we blindly grabbed the tracing provider

0 commit comments

Comments
 (0)