From 484e2ae446cac3f21e4cab2fc739728ac1fe9098 Mon Sep 17 00:00:00 2001 From: Andrei Solntsev Date: Thu, 4 Dec 2025 14:15:44 +0200 Subject: [PATCH] add nullability annotations in "*.bidi.log" package --- .../org/openqa/selenium/bidi/log/BUILD.bazel | 2 ++ .../selenium/bidi/log/BaseLogEntry.java | 8 ++++--- .../selenium/bidi/log/ConsoleLogEntry.java | 3 ++- .../selenium/bidi/log/GenericLogEntry.java | 7 +++++-- .../selenium/bidi/log/JavascriptLogEntry.java | 7 +++++-- .../selenium/bidi/log/package-info.java | 21 +++++++++++++++++++ .../selenium/bidi/log/LogInspectorTest.java | 6 +++--- 7 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 java/src/org/openqa/selenium/bidi/log/package-info.java diff --git a/java/src/org/openqa/selenium/bidi/log/BUILD.bazel b/java/src/org/openqa/selenium/bidi/log/BUILD.bazel index 062fcc0f14355..7e9b2a00b23c5 100644 --- a/java/src/org/openqa/selenium/bidi/log/BUILD.bazel +++ b/java/src/org/openqa/selenium/bidi/log/BUILD.bazel @@ -1,3 +1,4 @@ +load("@rules_jvm_external//:defs.bzl", "artifact") load("//java:defs.bzl", "java_library") java_library( @@ -19,5 +20,6 @@ java_library( "//java/src/org/openqa/selenium/bidi/script", "//java/src/org/openqa/selenium/json", "//java/src/org/openqa/selenium/remote/http", + artifact("org.jspecify:jspecify"), ], ) diff --git a/java/src/org/openqa/selenium/bidi/log/BaseLogEntry.java b/java/src/org/openqa/selenium/bidi/log/BaseLogEntry.java index 552b27134a447..296a0c89be60e 100644 --- a/java/src/org/openqa/selenium/bidi/log/BaseLogEntry.java +++ b/java/src/org/openqa/selenium/bidi/log/BaseLogEntry.java @@ -17,6 +17,7 @@ package org.openqa.selenium.bidi.log; +import org.jspecify.annotations.Nullable; import org.openqa.selenium.bidi.script.Source; // @see args, - StackTrace stackTrace) { + @Nullable StackTrace stackTrace) { super(level, source, text, timestamp, type, stackTrace); this.method = method; this.args = args; diff --git a/java/src/org/openqa/selenium/bidi/log/GenericLogEntry.java b/java/src/org/openqa/selenium/bidi/log/GenericLogEntry.java index a15a0af68bf1d..3bfbad1f68293 100644 --- a/java/src/org/openqa/selenium/bidi/log/GenericLogEntry.java +++ b/java/src/org/openqa/selenium/bidi/log/GenericLogEntry.java @@ -21,6 +21,7 @@ import java.util.Map; import java.util.TreeMap; +import org.jspecify.annotations.Nullable; import org.openqa.selenium.bidi.script.Source; import org.openqa.selenium.json.JsonInput; @@ -36,7 +37,7 @@ public GenericLogEntry( String text, long timestamp, String type, - StackTrace stackTrace) { + @Nullable StackTrace stackTrace) { super(level, source, text, timestamp, stackTrace); this.type = type; } @@ -97,7 +98,9 @@ private Map toJson() { toReturn.put("level", super.getLevel()); toReturn.put("text", super.getText()); toReturn.put("timestamp", super.getTimestamp()); - toReturn.put("stackTrace", super.getStackTrace()); + if (getStackTrace() != null) { + toReturn.put("stackTrace", getStackTrace()); + } return unmodifiableMap(toReturn); } diff --git a/java/src/org/openqa/selenium/bidi/log/JavascriptLogEntry.java b/java/src/org/openqa/selenium/bidi/log/JavascriptLogEntry.java index 5a1ca42f07636..2800d55070621 100644 --- a/java/src/org/openqa/selenium/bidi/log/JavascriptLogEntry.java +++ b/java/src/org/openqa/selenium/bidi/log/JavascriptLogEntry.java @@ -21,6 +21,7 @@ import java.util.Map; import java.util.TreeMap; +import org.jspecify.annotations.Nullable; import org.openqa.selenium.bidi.script.Source; import org.openqa.selenium.json.JsonInput; @@ -36,7 +37,7 @@ public JavascriptLogEntry( String text, long timestamp, String type, - StackTrace stackTrace) { + @Nullable StackTrace stackTrace) { super(level, source, text, timestamp, "javascript", stackTrace); this.type = "javascript"; } @@ -97,7 +98,9 @@ private Map toJson() { toReturn.put("level", super.getLevel()); toReturn.put("text", super.getText()); toReturn.put("timestamp", super.getTimestamp()); - toReturn.put("stackTrace", super.getStackTrace()); + if (getStackTrace() != null) { + toReturn.put("stackTrace", getStackTrace()); + } return unmodifiableMap(toReturn); } diff --git a/java/src/org/openqa/selenium/bidi/log/package-info.java b/java/src/org/openqa/selenium/bidi/log/package-info.java new file mode 100644 index 0000000000000..5c5d43834d469 --- /dev/null +++ b/java/src/org/openqa/selenium/bidi/log/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.bidi.log; + +import org.jspecify.annotations.NullMarked; diff --git a/java/test/org/openqa/selenium/bidi/log/LogInspectorTest.java b/java/test/org/openqa/selenium/bidi/log/LogInspectorTest.java index 5619a890b0fc1..65da3f19105a3 100644 --- a/java/test/org/openqa/selenium/bidi/log/LogInspectorTest.java +++ b/java/test/org/openqa/selenium/bidi/log/LogInspectorTest.java @@ -17,9 +17,9 @@ package org.openqa.selenium.bidi.log; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; -import static org.assertj.core.api.AssertionsForClassTypes.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.fail; import java.util.HashSet; import java.util.Set;