Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
-DaltSnapshotDeploymentRepository=repo.spring.io::default::https://repo.spring.io/libs-snapshot-local -P spring
-Djspecify.enabled=true
-P spring
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.Map;
import java.util.Objects;

import org.jspecify.annotations.Nullable;

/**
* Default implementation of {@link ServiceInstance}.
*
Expand All @@ -31,19 +33,19 @@
*/
public class DefaultServiceInstance implements ServiceInstance {

private String instanceId;
private @Nullable String instanceId;

private String serviceId;
private @Nullable String serviceId;

private String host;
private @Nullable String host;

private int port;

private boolean secure;

private Map<String, String> metadata = new LinkedHashMap<>();

private URI uri;
private @Nullable URI uri;

/**
* @param instanceId the id of the instance.
Expand All @@ -53,14 +55,16 @@ public class DefaultServiceInstance implements ServiceInstance {
* @param secure indicates whether or not the connection needs to be secure.
* @param metadata a map containing metadata.
*/
public DefaultServiceInstance(String instanceId, String serviceId, String host, int port, boolean secure,
Map<String, String> metadata) {
public DefaultServiceInstance(@Nullable String instanceId, @Nullable String serviceId, @Nullable String host,
int port, boolean secure, @Nullable Map<String, String> metadata) {
this.instanceId = instanceId;
this.serviceId = serviceId;
this.host = host;
this.port = port;
this.secure = secure;
this.metadata = metadata;
if (metadata != null) {
this.metadata = metadata;
}
}

/**
Expand All @@ -70,7 +74,8 @@ public DefaultServiceInstance(String instanceId, String serviceId, String host,
* @param port the port on which the service is running.
* @param secure indicates whether or not the connection needs to be secure.
*/
public DefaultServiceInstance(String instanceId, String serviceId, String host, int port, boolean secure) {
public DefaultServiceInstance(@Nullable String instanceId, @Nullable String serviceId, @Nullable String host,
int port, boolean secure) {
this(instanceId, serviceId, host, port, secure, new LinkedHashMap<>());
}

Expand Down Expand Up @@ -104,17 +109,17 @@ public Map<String, String> getMetadata() {
}

@Override
public String getInstanceId() {
public @Nullable String getInstanceId() {
return instanceId;
}

@Override
public String getServiceId() {
public @Nullable String getServiceId() {
return serviceId;
}

@Override
public String getHost() {
public @Nullable String getHost() {
return host;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public interface ServiceInstance {
/**
* @return The service ID as registered.
*/
String getServiceId();
@Nullable String getServiceId();

/**
* @return The hostname of the registered service instance.
*/
String getHost();
@Nullable String getHost();

/**
* @return The port of the registered service instance.
Expand All @@ -64,7 +64,7 @@ public interface ServiceInstance {
/**
* @return The key / value pair metadata associated with the service instance.
*/
Map<String, String> getMetadata();
@Nullable Map<String, String> getMetadata();

/**
* @return The scheme of the service instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
*/
final class CircuitBreakerConfigurerUtils {

/**
* Default fallback key.
*/
public static final String DEFAULT_FALLBACK_KEY = "default";

private CircuitBreakerConfigurerUtils() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public String[] selectImports(AnnotationMetadata metadata) {
AnnotationAttributes attributes = AnnotationAttributes
.fromMap(metadata.getAnnotationAttributes(getAnnotationClass().getName(), true));

boolean autoRegister = attributes.getBoolean("autoRegister");
boolean autoRegister = true;
if (attributes != null) {
autoRegister = attributes.getBoolean("autoRegister");
}

if (autoRegister) {
List<String> importsList = new ArrayList<>(Arrays.asList(imports));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.cloud.client.loadbalancer;

import org.jspecify.annotations.Nullable;

import org.springframework.core.style.ToStringCreator;

/**
Expand All @@ -29,11 +31,11 @@ public class CompletionContext<RES, T, C> {

private final Status status;

private final Throwable throwable;
private final @Nullable Throwable throwable;

private final Response<T> loadBalancerResponse;
private final @Nullable Response<T> loadBalancerResponse;

private final RES clientResponse;
private final @Nullable RES clientResponse;

private final Request<C> loadBalancerRequest;

Expand All @@ -55,8 +57,8 @@ public CompletionContext(Status status, Request<C> loadBalancerRequest, Response
this(status, null, loadBalancerRequest, loadBalancerResponse, clientResponse);
}

public CompletionContext(Status status, Throwable throwable, Request<C> loadBalancerRequest,
Response<T> loadBalancerResponse, RES clientResponse) {
public CompletionContext(Status status, @Nullable Throwable throwable, Request<C> loadBalancerRequest,
@Nullable Response<T> loadBalancerResponse, @Nullable RES clientResponse) {
this.status = status;
this.throwable = throwable;
this.loadBalancerRequest = loadBalancerRequest;
Expand All @@ -68,15 +70,15 @@ public Status status() {
return this.status;
}

public Throwable getThrowable() {
public @Nullable Throwable getThrowable() {
return this.throwable;
}

public Response<T> getLoadBalancerResponse() {
public @Nullable Response<T> getLoadBalancerResponse() {
return loadBalancerResponse;
}

public RES getClientResponse() {
public @Nullable RES getClientResponse() {
return clientResponse;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public class DefaultRequest<T> implements Request<T> {

private T context;

@SuppressWarnings("unchecked")
public DefaultRequest() {
new DefaultRequestContext();
this((T) new DefaultRequestContext());
}

public DefaultRequest(T context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.util.Objects;

import org.jspecify.annotations.Nullable;

import org.springframework.core.style.ToStringCreator;

/**
Expand All @@ -31,22 +33,22 @@ public class DefaultRequestContext extends HintRequestContext {
* The request to be executed against the service instance selected by the
* LoadBalancer.
*/
private final Object clientRequest;
private final @Nullable Object clientRequest;

public DefaultRequestContext() {
clientRequest = null;
}

public DefaultRequestContext(Object clientRequest) {
public DefaultRequestContext(@Nullable Object clientRequest) {
this.clientRequest = clientRequest;
}

public DefaultRequestContext(Object clientRequest, String hint) {
public DefaultRequestContext(@Nullable Object clientRequest, String hint) {
super(hint);
this.clientRequest = clientRequest;
}

public Object getClientRequest() {
public @Nullable Object getClientRequest() {
return clientRequest;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.util.Objects;

import org.jspecify.annotations.Nullable;

import org.springframework.cloud.client.ServiceInstance;
import org.springframework.core.style.ToStringCreator;

Expand All @@ -27,7 +29,7 @@
*/
public class DefaultResponse implements Response<ServiceInstance> {

private final ServiceInstance serviceInstance;
private final @Nullable ServiceInstance serviceInstance;

public DefaultResponse(ServiceInstance serviceInstance) {
this.serviceInstance = serviceInstance;
Expand All @@ -39,7 +41,7 @@ public boolean hasServer() {
}

@Override
public ServiceInstance getServer() {
public @Nullable ServiceInstance getServer() {
return this.serviceInstance;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.io.IOException;

import org.jspecify.annotations.Nullable;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
Expand All @@ -37,14 +39,15 @@ public class DeferringLoadBalancerInterceptor implements ClientHttpRequestInterc

private final ObjectProvider<BlockingLoadBalancerInterceptor> loadBalancerInterceptorProvider;

private BlockingLoadBalancerInterceptor delegate;
private @Nullable BlockingLoadBalancerInterceptor delegate;

public DeferringLoadBalancerInterceptor(
ObjectProvider<BlockingLoadBalancerInterceptor> loadBalancerInterceptorProvider) {
this.loadBalancerInterceptorProvider = loadBalancerInterceptorProvider;
}

@Override
@SuppressWarnings("NullAway") // nullability checked in tryResolveDelegate()
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
throws IOException {
tryResolveDelegate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.cloud.client.loadbalancer;

import org.jspecify.annotations.Nullable;

import org.springframework.cloud.client.ServiceInstance;

/**
Expand All @@ -29,7 +31,7 @@ public boolean hasServer() {
}

@Override
public ServiceInstance getServer() {
public @Nullable ServiceInstance getServer() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.net.URI;

import org.jspecify.annotations.Nullable;

import org.springframework.retry.RecoveryCallback;
import org.springframework.retry.RetryContext;
import org.springframework.retry.RetryException;
Expand All @@ -39,8 +41,9 @@ public abstract class LoadBalancedRecoveryCallback<T, R> implements RecoveryCall
* @param uri The URI the response is from.
* @return The response to be returned.
*/
protected abstract T createResponse(R response, URI uri);
protected abstract T createResponse(R response, @Nullable URI uri);

@SuppressWarnings("unchecked")
@Override
public T recover(RetryContext context) throws Exception {
Throwable lastThrowable = context.getLastThrowable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.cloud.client.loadbalancer;

import org.jspecify.annotations.Nullable;

import org.springframework.cloud.client.ServiceInstance;
import org.springframework.http.HttpRequest;
import org.springframework.retry.RetryContext;
Expand All @@ -31,9 +33,9 @@ public class LoadBalancedRetryContext extends RetryContextSupport {

private HttpRequest request;

private ServiceInstance serviceInstance;
private @Nullable ServiceInstance serviceInstance;

private ServiceInstance previousServiceInstance;
private @Nullable ServiceInstance previousServiceInstance;

/**
* Creates a new load-balanced context.
Expand Down Expand Up @@ -65,24 +67,24 @@ public void setRequest(HttpRequest request) {
* Gets the service instance used during the retry.
* @return The service instance used during the retry.
*/
public ServiceInstance getServiceInstance() {
public @Nullable ServiceInstance getServiceInstance() {
return this.serviceInstance;
}

/**
* Sets the service instance to use during the retry.
* @param serviceInstance The service instance to use during the retry.
*/
public void setServiceInstance(ServiceInstance serviceInstance) {
public void setServiceInstance(@Nullable ServiceInstance serviceInstance) {
setPreviousServiceInstance(this.serviceInstance);
this.serviceInstance = serviceInstance;
}

public ServiceInstance getPreviousServiceInstance() {
public @Nullable ServiceInstance getPreviousServiceInstance() {
return previousServiceInstance;
}

public void setPreviousServiceInstance(ServiceInstance previousServiceInstance) {
public void setPreviousServiceInstance(@Nullable ServiceInstance previousServiceInstance) {
this.previousServiceInstance = previousServiceInstance;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ default RetryListener[] createRetryListeners(String service) {
* @param service The service to create the {@link BackOffPolicy} for.
* @return The {@link BackOffPolicy}.
*/
default BackOffPolicy createBackOffPolicy(String service) {
default @Nullable BackOffPolicy createBackOffPolicy(String service) {
return new NoBackOffPolicy();
}

Expand Down
Loading
Loading