Add nullability annotations to module/spring-boot-h2console

See gh-46587
This commit is contained in:
Moritz Halbritter 2025-07-31 10:24:59 +02:00
parent a044d91590
commit 73abf7f474
3 changed files with 10 additions and 4 deletions

View File

@ -25,6 +25,7 @@ import javax.sql.DataSource;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.h2.server.web.JakartaWebServlet; import org.h2.server.web.JakartaWebServlet;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfiguration;
@ -118,7 +119,7 @@ public final class H2ConsoleAutoConfiguration {
.toList(); .toList();
} }
private String getConnectionUrl(DataSource dataSource) { private @Nullable String getConnectionUrl(DataSource dataSource) {
try (Connection connection = dataSource.getConnection()) { try (Connection connection = dataSource.getConnection()) {
return "'" + connection.getMetaData().getURL() + "'"; return "'" + connection.getMetaData().getURL() + "'";
} }

View File

@ -16,6 +16,8 @@
package org.springframework.boot.h2console.autoconfigure; package org.springframework.boot.h2console.autoconfigure;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -80,7 +82,7 @@ public class H2ConsoleProperties {
/** /**
* Password to access preferences and tools of H2 Console. * Password to access preferences and tools of H2 Console.
*/ */
private String webAdminPassword; private @Nullable String webAdminPassword;
public boolean isTrace() { public boolean isTrace() {
return this.trace; return this.trace;
@ -98,11 +100,11 @@ public class H2ConsoleProperties {
this.webAllowOthers = webAllowOthers; this.webAllowOthers = webAllowOthers;
} }
public String getWebAdminPassword() { public @Nullable String getWebAdminPassword() {
return this.webAdminPassword; return this.webAdminPassword;
} }
public void setWebAdminPassword(String webAdminPassword) { public void setWebAdminPassword(@Nullable String webAdminPassword) {
this.webAdminPassword = webAdminPassword; this.webAdminPassword = webAdminPassword;
} }

View File

@ -17,4 +17,7 @@
/** /**
* Auto-configuration for H2's Console. * Auto-configuration for H2's Console.
*/ */
@NullMarked
package org.springframework.boot.h2console.autoconfigure; package org.springframework.boot.h2console.autoconfigure;
import org.jspecify.annotations.NullMarked;