Add nullability annotations to smoke-test/spring-boot-smoke-test-bootstrap-registry

See gh-46587
This commit is contained in:
Moritz Halbritter 2025-08-12 09:46:27 +02:00
parent cdb295927a
commit d63955d4f1
8 changed files with 47 additions and 13 deletions

View File

@ -16,12 +16,13 @@
package smoketest.bootstrapregistry.app;
import org.jspecify.annotations.Nullable;
import smoketest.bootstrapregistry.external.svn.SubversionClient;
import smoketest.bootstrapregistry.external.svn.SubversionServerCertificate;
public class MySubversionClient extends SubversionClient {
public MySubversionClient(SubversionServerCertificate serverCertificate) {
public MySubversionClient(@Nullable SubversionServerCertificate serverCertificate) {
super(serverCertificate);
}

View File

@ -0,0 +1,20 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed 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
*
* https://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 smoketest.bootstrapregistry.app;
import org.jspecify.annotations.NullMarked;

View File

@ -18,6 +18,8 @@ package smoketest.bootstrapregistry.external.svn;
import java.util.function.Function;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.BootstrapContext;
import org.springframework.boot.BootstrapRegistryInitializer;
@ -38,13 +40,13 @@ public final class SubversionBootstrap {
* @return a {@link BootstrapRegistryInitializer} instance
*/
public static BootstrapRegistryInitializer withCustomClient(
Function<SubversionServerCertificate, SubversionClient> clientFactory) {
Function<@Nullable SubversionServerCertificate, SubversionClient> clientFactory) {
return (registry) -> registry.register(SubversionClient.class,
(bootstrapContext) -> createSubversionClient(bootstrapContext, clientFactory));
}
private static SubversionClient createSubversionClient(BootstrapContext bootstrapContext,
Function<SubversionServerCertificate, SubversionClient> clientFactory) {
Function<@Nullable SubversionServerCertificate, SubversionClient> clientFactory) {
return clientFactory.apply(bootstrapContext.get(SubversionServerCertificate.class));
}

View File

@ -16,6 +16,8 @@
package smoketest.bootstrapregistry.external.svn;
import org.jspecify.annotations.Nullable;
/**
* A client that can connect to a subversion server.
*
@ -23,9 +25,9 @@ package smoketest.bootstrapregistry.external.svn;
*/
public class SubversionClient {
private final SubversionServerCertificate serverCertificate;
private final @Nullable SubversionServerCertificate serverCertificate;
public SubversionClient(SubversionServerCertificate serverCertificate) {
public SubversionClient(@Nullable SubversionServerCertificate serverCertificate) {
this.serverCertificate = serverCertificate;
}

View File

@ -30,6 +30,7 @@ import org.springframework.boot.context.config.ConfigDataLocationNotFoundExcepti
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.util.Assert;
/**
* {@link ConfigDataLoader} for subversion.
@ -55,15 +56,16 @@ class SubversionConfigDataLoader implements ConfigDataLoader<SubversionConfigDat
context.getBootstrapContext()
.registerIfAbsent(SubversionServerCertificate.class, InstanceSupplier.of(resource.getServerCertificate()));
SubversionClient client = context.getBootstrapContext().get(SubversionClient.class);
Assert.state(client != null, "'client' must not be null");
String loaded = client.load(resource.getLocation());
PropertySource<?> propertySource = new MapPropertySource("svn", Collections.singletonMap("svn", loaded));
return new ConfigData(Collections.singleton(propertySource));
}
private static void onBootstrapContextClosed(BootstrapContextClosedEvent event) {
event.getApplicationContext()
.getBeanFactory()
.registerSingleton("subversionClient", event.getBootstrapContext().get(SubversionClient.class));
SubversionClient subversionClient = event.getBootstrapContext().get(SubversionClient.class);
Assert.state(subversionClient != null, "'subversionClient' must not be null");
event.getApplicationContext().getBeanFactory().registerSingleton("subversionClient", subversionClient);
}
}

View File

@ -16,6 +16,8 @@
package smoketest.bootstrapregistry.external.svn;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.context.config.ConfigDataResource;
/**
@ -27,9 +29,9 @@ class SubversionConfigDataResource extends ConfigDataResource {
private final String location;
private final SubversionServerCertificate serverCertificate;
private final @Nullable SubversionServerCertificate serverCertificate;
SubversionConfigDataResource(String location, String serverCertificate) {
SubversionConfigDataResource(String location, @Nullable String serverCertificate) {
this.location = location;
this.serverCertificate = SubversionServerCertificate.of(serverCertificate);
}
@ -38,12 +40,12 @@ class SubversionConfigDataResource extends ConfigDataResource {
return this.location;
}
SubversionServerCertificate getServerCertificate() {
@Nullable SubversionServerCertificate getServerCertificate() {
return this.serverCertificate;
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}

View File

@ -16,6 +16,8 @@
package smoketest.bootstrapregistry.external.svn;
import org.jspecify.annotations.Nullable;
import org.springframework.util.StringUtils;
/**
@ -36,7 +38,7 @@ public class SubversionServerCertificate {
return this.data;
}
public static SubversionServerCertificate of(String data) {
public static @Nullable SubversionServerCertificate of(@Nullable String data) {
return StringUtils.hasText(data) ? new SubversionServerCertificate(data) : null;
}

View File

@ -17,4 +17,7 @@
/**
* An example of a hypothetical library that supports subversion.
*/
@NullMarked
package smoketest.bootstrapregistry.external.svn;
import org.jspecify.annotations.NullMarked;