From 31d18eb9c4001503e6196ba2a1f642a3be7be7fe Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Fri, 14 Nov 2025 10:13:31 -0500 Subject: [PATCH] Initial implementation of nullability and JSpecify --- .mvn/jvm.config | 12 ++++++++++- pom.xml | 1 + .../client/KubernetesClientPodUtils.java | 3 ++- .../client/config/package-info.java | 21 +++++++++++++++++++ .../client/discovery/package-info.java | 21 +++++++++++++++++++ ...KubernetesClientServiceInstanceMapper.java | 3 ++- .../client/loadbalancer/package-info.java | 21 +++++++++++++++++++ .../commons/KubernetesNamespaceProvider.java | 8 ++++--- .../config/CommonPropertySourceLocator.java | 3 ++- ...ivationAwareYamlPropertiesFactoryBean.java | 2 +- .../commons/config/package-info.java | 21 +++++++++++++++++++ .../discovery/DiscoveryClientUtils.java | 4 ++-- .../discovery/ServicePortNameAndNumber.java | 2 +- .../commons/discovery/package-info.java | 21 +++++++++++++++++++ .../commons/leader/LeadershipController.java | 4 +++- .../commons/loadbalancer/package-info.java | 21 +++++++++++++++++++ .../kubernetes/commons/package-info.java | 21 +++++++++++++++++++ .../cloud/kubernetes/package-info.java | 21 +++++++++++++++++++ .../kubernetes/discovery/package-info.java | 21 +++++++++++++++++++ .../kubernetes/fabric8/Fabric8PodUtils.java | 3 ++- .../kubernetes/fabric8/Fabric8Utils.java | 2 +- .../fabric8/config/package-info.java | 21 +++++++++++++++++++ .../Fabric8DiscoveryClientUtils.java | 2 +- .../fabric8/discovery/package-info.java | 21 +++++++++++++++++++ .../leader/Fabric8LeadershipController.java | 3 ++- .../Fabric8ServiceInstanceMapper.java | 3 ++- .../fabric8/loadbalancer/package-info.java | 21 +++++++++++++++++++ .../tests/commons/fabric8_client/Util.java | 2 +- .../tests/commons/native_client/Util.java | 2 +- 29 files changed, 292 insertions(+), 19 deletions(-) create mode 100644 spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/package-info.java create mode 100644 spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/package-info.java create mode 100644 spring-cloud-kubernetes-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/client/loadbalancer/package-info.java create mode 100644 spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/package-info.java create mode 100644 spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/package-info.java create mode 100644 spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/loadbalancer/package-info.java create mode 100644 spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/package-info.java create mode 100644 spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/package-info.java create mode 100644 spring-cloud-kubernetes-discovery/src/main/java/org/springframework/cloud/kubernetes/discovery/package-info.java create mode 100644 spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/package-info.java create mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/package-info.java create mode 100644 spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/package-info.java diff --git a/.mvn/jvm.config b/.mvn/jvm.config index 0e7dabeff6..761912e40d 100644 --- a/.mvn/jvm.config +++ b/.mvn/jvm.config @@ -1 +1,11 @@ --Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom \ No newline at end of file +-Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom +--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED +--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED +--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED +--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED +--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED +--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED +--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED +--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED +--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED +--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED \ No newline at end of file diff --git a/pom.xml b/pom.xml index 7a57b429df..54894c65ab 100644 --- a/pom.xml +++ b/pom.xml @@ -101,6 +101,7 @@ true + true diff --git a/spring-cloud-kubernetes-client-autoconfig/src/main/java/org/springframework/cloud/kubernetes/client/KubernetesClientPodUtils.java b/spring-cloud-kubernetes-client-autoconfig/src/main/java/org/springframework/cloud/kubernetes/client/KubernetesClientPodUtils.java index 3ca97f5070..fdd9553650 100644 --- a/spring-cloud-kubernetes-client-autoconfig/src/main/java/org/springframework/cloud/kubernetes/client/KubernetesClientPodUtils.java +++ b/spring-cloud-kubernetes-client-autoconfig/src/main/java/org/springframework/cloud/kubernetes/client/KubernetesClientPodUtils.java @@ -25,6 +25,7 @@ import io.kubernetes.client.util.Config; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.cloud.kubernetes.commons.EnvReader; import org.springframework.cloud.kubernetes.commons.LazilyInstantiate; @@ -75,7 +76,7 @@ public boolean isInsideKubernetes() { return currentPod().get() != null; } - private V1Pod internalGetPod() { + private @Nullable V1Pod internalGetPod() { try { if (isServiceHostEnvVarPresent() && isHostNameEnvVarPresent() && isServiceAccountFound()) { LOG.debug("reading pod in namespace : " + namespace); diff --git a/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/package-info.java b/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/package-info.java new file mode 100644 index 0000000000..fc98dc0b74 --- /dev/null +++ b/spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2013-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. + */ + +/** + * Spring Cloud Kubernetes client config implementations. + */ +@org.jspecify.annotations.NullMarked +package org.springframework.cloud.kubernetes.client.config; diff --git a/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/package-info.java b/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/package-info.java new file mode 100644 index 0000000000..429f00c6f6 --- /dev/null +++ b/spring-cloud-kubernetes-client-discovery/src/main/java/org/springframework/cloud/kubernetes/client/discovery/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2013-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. + */ + +/** + * Spring Cloud Kubernetes client discovery implementations. + */ +@org.jspecify.annotations.NullMarked +package org.springframework.cloud.kubernetes.client.discovery; diff --git a/spring-cloud-kubernetes-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServiceInstanceMapper.java b/spring-cloud-kubernetes-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServiceInstanceMapper.java index 8cf3871a6b..dad5db718d 100644 --- a/spring-cloud-kubernetes-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServiceInstanceMapper.java +++ b/spring-cloud-kubernetes-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServiceInstanceMapper.java @@ -26,6 +26,7 @@ import io.kubernetes.client.openapi.models.V1ServicePort; import io.kubernetes.client.openapi.models.V1ServiceSpec; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance; import org.springframework.cloud.kubernetes.commons.discovery.DiscoveryClientUtils; @@ -71,7 +72,7 @@ public KubernetesClientServiceInstanceMapper(KubernetesLoadBalancerProperties pr } @Override - public KubernetesServiceInstance map(V1Service service) { + public @Nullable KubernetesServiceInstance map(V1Service service) { V1ObjectMeta metadata = service.getMetadata(); List ports = ofNullable(service.getSpec()).map(V1ServiceSpec::getPorts).orElse(List.of()); diff --git a/spring-cloud-kubernetes-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/client/loadbalancer/package-info.java b/spring-cloud-kubernetes-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/client/loadbalancer/package-info.java new file mode 100644 index 0000000000..a83eca5313 --- /dev/null +++ b/spring-cloud-kubernetes-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/client/loadbalancer/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2013-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. + */ + +/** + * Spring Cloud Kubernetes client load balancer implementations. + */ +@org.jspecify.annotations.NullMarked +package org.springframework.cloud.kubernetes.client.loadbalancer; diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/KubernetesNamespaceProvider.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/KubernetesNamespaceProvider.java index 3b43017e1c..ce52798704 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/KubernetesNamespaceProvider.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/KubernetesNamespaceProvider.java @@ -21,6 +21,8 @@ import java.nio.file.Path; import java.nio.file.Paths; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.context.properties.bind.BindHandler; import org.springframework.boot.context.properties.bind.Bindable; import org.springframework.boot.context.properties.bind.Binder; @@ -71,7 +73,7 @@ public KubernetesNamespaceProvider(String namespacePropertyValue) { this.namespacePropertyValue = namespacePropertyValue; } - public static String getNamespaceFromServiceAccountFile(String path) { + public static @Nullable String getNamespaceFromServiceAccountFile(String path) { String namespace = null; LOG.debug("Looking for service account namespace at: [" + path + "]."); Path serviceAccountNamespacePath = Paths.get(path); @@ -91,7 +93,7 @@ public static String getNamespaceFromServiceAccountFile(String path) { return namespace; } - public String getNamespace() { + public @Nullable String getNamespace() { // If they provided the namespace in the constructor just return that if (!ObjectUtils.isEmpty(namespacePropertyValue)) { return namespacePropertyValue; @@ -107,7 +109,7 @@ public String getNamespace() { return namespace != null ? namespace : getServiceAccountNamespace(); } - private String getServiceAccountNamespace() { + private @Nullable String getServiceAccountNamespace() { String serviceAccountNamespacePathString = null; if (environment != null) { serviceAccountNamespacePathString = environment.getProperty(NAMESPACE_PATH_PROPERTY, diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java index 357b315d53..31fd46ec80 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java @@ -23,6 +23,7 @@ import java.util.Set; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.cloud.bootstrap.config.PropertySourceLocator; import org.springframework.core.env.CompositePropertySource; @@ -52,7 +53,7 @@ protected abstract MapPropertySource getPropertySource(ConfigurableEnvironment e NormalizedSource normalizedSource, ReadType readType); @Override - public PropertySource locate(Environment environment) { + public @Nullable PropertySource locate(Environment environment) { if (environment instanceof ConfigurableEnvironment env) { diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ProfileActivationAwareYamlPropertiesFactoryBean.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ProfileActivationAwareYamlPropertiesFactoryBean.java index 98aaf6f34e..f811828b90 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ProfileActivationAwareYamlPropertiesFactoryBean.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ProfileActivationAwareYamlPropertiesFactoryBean.java @@ -28,8 +28,8 @@ import java.util.Properties; import java.util.stream.Collectors; -import jakarta.annotation.Nullable; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.reader.UnicodeReader; diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/package-info.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/package-info.java new file mode 100644 index 0000000000..8f205ec659 --- /dev/null +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2013-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. + */ + +/** + * Spring Cloud Kubernetes configuration abstractions. + */ +@org.jspecify.annotations.NullMarked +package org.springframework.cloud.kubernetes.commons.config; diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/DiscoveryClientUtils.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/DiscoveryClientUtils.java index f7075e5387..b70b53e65f 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/DiscoveryClientUtils.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/DiscoveryClientUtils.java @@ -23,8 +23,8 @@ import java.util.function.Supplier; import java.util.stream.Collectors; -import jakarta.annotation.Nullable; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.cloud.client.ServiceInstance; import org.springframework.core.log.LogAccessor; @@ -173,7 +173,7 @@ public static ServiceInstance externalNameServiceInstance(ServiceMetadata servic * take primary-port-name from service label "PRIMARY_PORT_NAME_LABEL_KEY" if it * exists, otherwise from KubernetesDiscoveryProperties if it exists, otherwise null. */ - static String primaryPortName(KubernetesDiscoveryProperties properties, Map serviceLabels, + static @Nullable String primaryPortName(KubernetesDiscoveryProperties properties, Map serviceLabels, String serviceId) { String primaryPortNameFromProperties = properties.primaryPortName(); diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ServicePortNameAndNumber.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ServicePortNameAndNumber.java index ab60f9fa2c..c514d07d5e 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ServicePortNameAndNumber.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ServicePortNameAndNumber.java @@ -16,7 +16,7 @@ package org.springframework.cloud.kubernetes.commons.discovery; -import jakarta.annotation.Nullable; +import org.jspecify.annotations.Nullable; /** * @author wind57 diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/package-info.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/package-info.java new file mode 100644 index 0000000000..3f2d9b79ce --- /dev/null +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2013-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. + */ + +/** + * Spring Cloud Kubernetes discovery abstractions. + */ +@org.jspecify.annotations.NullMarked +package org.springframework.cloud.kubernetes.commons.discovery; diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/leader/LeadershipController.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/leader/LeadershipController.java index f118063b7d..602c538805 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/leader/LeadershipController.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/leader/LeadershipController.java @@ -21,6 +21,8 @@ import java.util.Objects; import java.util.Optional; +import org.jspecify.annotations.Nullable; + import org.springframework.core.log.LogAccessor; import org.springframework.integration.leader.Candidate; import org.springframework.integration.leader.Context; @@ -76,7 +78,7 @@ protected Map getLeaderData(Candidate candidate) { return Collections.singletonMap(leaderKey, candidate.getId()); } - protected Leader extractLeader(Map data) { + protected @Nullable Leader extractLeader(@Nullable Map data) { if (data == null) { return null; } diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/loadbalancer/package-info.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/loadbalancer/package-info.java new file mode 100644 index 0000000000..f5164fdc51 --- /dev/null +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/loadbalancer/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2013-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. + */ + +/** + * Spring Cloud Kubernetes load balancer abstractions. + */ +@org.jspecify.annotations.NullMarked +package org.springframework.cloud.kubernetes.commons.loadbalancer; diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/package-info.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/package-info.java new file mode 100644 index 0000000000..1edb370ac2 --- /dev/null +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2013-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. + */ + +/** + * Spring Cloud Kubernetes commons utilities and abstractions. + */ +@org.jspecify.annotations.NullMarked +package org.springframework.cloud.kubernetes.commons; diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/package-info.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/package-info.java new file mode 100644 index 0000000000..e2726fafaa --- /dev/null +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2013-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. + */ + +/** + * Spring Cloud Kubernetes abstractions. + */ +@org.jspecify.annotations.NullMarked +package org.springframework.cloud.kubernetes; diff --git a/spring-cloud-kubernetes-discovery/src/main/java/org/springframework/cloud/kubernetes/discovery/package-info.java b/spring-cloud-kubernetes-discovery/src/main/java/org/springframework/cloud/kubernetes/discovery/package-info.java new file mode 100644 index 0000000000..a291005f2e --- /dev/null +++ b/spring-cloud-kubernetes-discovery/src/main/java/org/springframework/cloud/kubernetes/discovery/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2013-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. + */ + +/** + * Spring Cloud Kubernetes discovery client abstractions. + */ +@org.jspecify.annotations.NullMarked +package org.springframework.cloud.kubernetes.discovery; diff --git a/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8PodUtils.java b/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8PodUtils.java index ad1f562f1c..e5dade2cb9 100644 --- a/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8PodUtils.java +++ b/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8PodUtils.java @@ -24,6 +24,7 @@ import io.fabric8.kubernetes.client.KubernetesClient; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.cloud.kubernetes.commons.EnvReader; import org.springframework.cloud.kubernetes.commons.LazilyInstantiate; @@ -68,7 +69,7 @@ public boolean isInsideKubernetes() { return currentPod().get() != null; } - private Pod internalGetPod() { + private @Nullable Pod internalGetPod() { try { if (isServiceHostEnvVarPresent() && isHostNameEnvVarPresent() && isServiceAccountFound()) { return this.client.pods().withName(this.hostName).get(); diff --git a/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8Utils.java b/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8Utils.java index 8c0ef32e33..08a65367a1 100644 --- a/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8Utils.java +++ b/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8Utils.java @@ -20,8 +20,8 @@ import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.api.model.ServiceSpec; import io.fabric8.kubernetes.client.KubernetesClient; -import jakarta.annotation.Nullable; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.config.NamespaceResolutionFailedException; diff --git a/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/package-info.java b/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/package-info.java new file mode 100644 index 0000000000..41de79bcd1 --- /dev/null +++ b/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2013-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. + */ + +/** + * Spring Cloud Kubernetes Fabric8 config implementations. + */ +@org.jspecify.annotations.NullMarked +package org.springframework.cloud.kubernetes.fabric8.config; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientUtils.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientUtils.java index dcac8b50a2..cf28ab89bf 100644 --- a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientUtils.java +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8DiscoveryClientUtils.java @@ -38,8 +38,8 @@ import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.ServiceResource; -import jakarta.annotation.Nullable; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/package-info.java b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/package-info.java new file mode 100644 index 0000000000..ec7aa2a4ad --- /dev/null +++ b/spring-cloud-kubernetes-fabric8-discovery/src/main/java/org/springframework/cloud/kubernetes/fabric8/discovery/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2013-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. + */ + +/** + * Spring Cloud Kubernetes Fabric8 discovery implementations. + */ +@org.jspecify.annotations.NullMarked +package org.springframework.cloud.kubernetes.fabric8.discovery; diff --git a/spring-cloud-kubernetes-fabric8-leader/src/main/java/org/springframework/cloud/kubernetes/fabric8/leader/Fabric8LeadershipController.java b/spring-cloud-kubernetes-fabric8-leader/src/main/java/org/springframework/cloud/kubernetes/fabric8/leader/Fabric8LeadershipController.java index 5712573793..29017669d0 100644 --- a/spring-cloud-kubernetes-fabric8-leader/src/main/java/org/springframework/cloud/kubernetes/fabric8/leader/Fabric8LeadershipController.java +++ b/spring-cloud-kubernetes-fabric8-leader/src/main/java/org/springframework/cloud/kubernetes/fabric8/leader/Fabric8LeadershipController.java @@ -23,6 +23,7 @@ import io.fabric8.kubernetes.api.model.ConfigMapBuilder; import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientException; +import org.jspecify.annotations.Nullable; import org.springframework.cloud.kubernetes.commons.leader.Leader; import org.springframework.cloud.kubernetes.commons.leader.LeaderProperties; @@ -136,7 +137,7 @@ protected PodReadinessWatcher createPodReadinessWatcher(String localLeaderId) { return new Fabric8PodReadinessWatcher(localLeaderId, kubernetesClient, this); } - private Leader extractLeader(ConfigMap configMap) { + private @Nullable Leader extractLeader(@Nullable ConfigMap configMap) { if (configMap == null) { return null; } diff --git a/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServiceInstanceMapper.java b/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServiceInstanceMapper.java index f04e655c07..47c95ea2f4 100644 --- a/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServiceInstanceMapper.java +++ b/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/Fabric8ServiceInstanceMapper.java @@ -25,6 +25,7 @@ import io.fabric8.kubernetes.api.model.Service; import io.fabric8.kubernetes.api.model.ServicePort; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance; import org.springframework.cloud.kubernetes.commons.discovery.DiscoveryClientUtils; @@ -71,7 +72,7 @@ public class Fabric8ServiceInstanceMapper implements KubernetesServiceInstanceMa } @Override - public KubernetesServiceInstance map(Service service) { + public @Nullable KubernetesServiceInstance map(Service service) { ObjectMeta metadata = service.getMetadata(); List ports = service.getSpec().getPorts(); ServicePort port; diff --git a/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/package-info.java b/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/package-info.java new file mode 100644 index 0000000000..5599cd8159 --- /dev/null +++ b/spring-cloud-kubernetes-fabric8-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/fabric8/loadbalancer/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2013-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. + */ + +/** + * Spring Cloud Kubernetes Fabric8 load balancer implementations. + */ +@org.jspecify.annotations.NullMarked +package org.springframework.cloud.kubernetes.fabric8.loadbalancer; diff --git a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client/Util.java b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client/Util.java index d28563b8af..a016ea6517 100644 --- a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client/Util.java +++ b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client/Util.java @@ -37,9 +37,9 @@ import io.fabric8.kubernetes.client.KubernetesClient; import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.fabric8.kubernetes.client.utils.Serialization; -import jakarta.annotation.Nullable; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.testcontainers.k3s.K3sContainer; import org.springframework.cloud.kubernetes.integration.tests.commons.Images; diff --git a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/native_client/Util.java b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/native_client/Util.java index 313ccb8188..11a2885260 100644 --- a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/native_client/Util.java +++ b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/native_client/Util.java @@ -49,10 +49,10 @@ import io.kubernetes.client.openapi.models.V1ServiceAccount; import io.kubernetes.client.util.Config; import io.kubernetes.client.util.Yaml; -import jakarta.annotation.Nullable; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.assertj.core.api.Assertions; +import org.jspecify.annotations.Nullable; import org.testcontainers.k3s.K3sContainer; import org.springframework.cloud.kubernetes.integration.tests.commons.Images;