2929import java .util .List ;
3030import java .util .function .Function ;
3131import java .util .function .Supplier ;
32+ import org .jspecify .annotations .Nullable ;
3233import org .openqa .selenium .TimeoutException ;
3334import org .openqa .selenium .WebDriverException ;
3435import org .openqa .selenium .internal .Require ;
@@ -76,7 +77,7 @@ public class FluentWait<T> implements Wait<T> {
7677
7778 protected Duration timeout = DEFAULT_WAIT_DURATION ;
7879 protected Duration interval = DEFAULT_WAIT_DURATION ;
79- protected Supplier <String > messageSupplier = () -> null ;
80+ protected Supplier <@ Nullable String > messageSupplier = () -> null ;
8081
8182 protected final List <Class <? extends Throwable >> ignoredExceptions = new ArrayList <>();
8283
@@ -117,6 +118,7 @@ public FluentWait<T> withTimeout(Duration timeout) {
117118 * @return A self reference.
118119 */
119120 public FluentWait <T > withMessage (final String message ) {
121+ Require .nonNull ("Message" , message );
120122 this .messageSupplier = () -> message ;
121123 return this ;
122124 }
@@ -128,7 +130,7 @@ public FluentWait<T> withMessage(final String message) {
128130 * @return A self reference.
129131 */
130132 public FluentWait <T > withMessage (Supplier <String > messageSupplier ) {
131- this .messageSupplier = messageSupplier ;
133+ this .messageSupplier = Require . nonNull ( "Message supplier" , messageSupplier ) ;
132134 return this ;
133135 }
134136
@@ -165,7 +167,7 @@ public <K extends Throwable> FluentWait<T> ignoreAll(Collection<Class<? extends
165167 * @see #ignoreAll(Collection)
166168 */
167169 public FluentWait <T > ignoring (Class <? extends Throwable > exceptionType ) {
168- return this .ignoreAll (List .< Class <? extends Throwable >> of (exceptionType ));
170+ return this .ignoreAll (List .of (exceptionType ));
169171 }
170172
171173 /**
@@ -198,7 +200,7 @@ public FluentWait<T> ignoring(
198200 * @throws TimeoutException If the timeout expires.
199201 */
200202 @ Override
201- public <V > V until (Function <? super T , V > isTrue ) {
203+ public <V > V until (Function <? super T , @ Nullable V > isTrue ) {
202204 Instant end = clock .instant ().plus (timeout );
203205
204206 Throwable lastException ;
@@ -220,7 +222,7 @@ public <V> V until(Function<? super T, V> isTrue) {
220222 // Check the timeout after evaluating the function to ensure conditions
221223 // with a zero timeout can succeed.
222224 if (end .isBefore (clock .instant ())) {
223- String message = messageSupplier != null ? messageSupplier .get () : null ;
225+ String message = messageSupplier .get ();
224226
225227 String timeoutMessage =
226228 String .format (
@@ -272,7 +274,7 @@ private Throwable propagateIfNotIgnored(Throwable e) {
272274 * on a function.
273275 * @return Nothing will ever be returned; this return type is only specified as a convenience.
274276 */
275- protected RuntimeException timeoutException (String message , Throwable lastException ) {
277+ protected RuntimeException timeoutException (String message , @ Nullable Throwable lastException ) {
276278 throw new TimeoutException (message , lastException );
277279 }
278280}
0 commit comments