From 73abf7f47486e5247abd37ea08e0354e039a7966 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Thu, 31 Jul 2025 10:24:59 +0200 Subject: [PATCH] Add nullability annotations to module/spring-boot-h2console See gh-46587 --- .../autoconfigure/H2ConsoleAutoConfiguration.java | 3 ++- .../boot/h2console/autoconfigure/H2ConsoleProperties.java | 8 +++++--- .../boot/h2console/autoconfigure/package-info.java | 3 +++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/module/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/H2ConsoleAutoConfiguration.java b/module/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/H2ConsoleAutoConfiguration.java index 445f35e2a46..cfda8666bfd 100644 --- a/module/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/H2ConsoleAutoConfiguration.java +++ b/module/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/H2ConsoleAutoConfiguration.java @@ -25,6 +25,7 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.h2.server.web.JakartaWebServlet; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfiguration; @@ -118,7 +119,7 @@ public final class H2ConsoleAutoConfiguration { .toList(); } - private String getConnectionUrl(DataSource dataSource) { + private @Nullable String getConnectionUrl(DataSource dataSource) { try (Connection connection = dataSource.getConnection()) { return "'" + connection.getMetaData().getURL() + "'"; } diff --git a/module/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/H2ConsoleProperties.java b/module/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/H2ConsoleProperties.java index 5244a2a5b2c..941cc7d2b9d 100644 --- a/module/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/H2ConsoleProperties.java +++ b/module/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/H2ConsoleProperties.java @@ -16,6 +16,8 @@ package org.springframework.boot.h2console.autoconfigure; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.util.Assert; @@ -80,7 +82,7 @@ public class H2ConsoleProperties { /** * Password to access preferences and tools of H2 Console. */ - private String webAdminPassword; + private @Nullable String webAdminPassword; public boolean isTrace() { return this.trace; @@ -98,11 +100,11 @@ public class H2ConsoleProperties { this.webAllowOthers = webAllowOthers; } - public String getWebAdminPassword() { + public @Nullable String getWebAdminPassword() { return this.webAdminPassword; } - public void setWebAdminPassword(String webAdminPassword) { + public void setWebAdminPassword(@Nullable String webAdminPassword) { this.webAdminPassword = webAdminPassword; } diff --git a/module/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/package-info.java b/module/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/package-info.java index 2b77c897be1..e872960b8ee 100644 --- a/module/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/package-info.java +++ b/module/spring-boot-h2console/src/main/java/org/springframework/boot/h2console/autoconfigure/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for H2's Console. */ +@NullMarked package org.springframework.boot.h2console.autoconfigure; + +import org.jspecify.annotations.NullMarked;