Skip to content

Commit db44a21

Browse files
committed
Initial implementation of nullability and JSpecify
1 parent 1e46b0c commit db44a21

File tree

30 files changed

+292
-20
lines changed

30 files changed

+292
-20
lines changed

.mvn/jvm.config

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
-Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom
1+
-Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom
2+
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
3+
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
4+
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
5+
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
6+
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
7+
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
8+
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
9+
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
10+
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
11+
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
</maven-checkstyle-plugin.failsOnViolation>
102102
<maven-checkstyle-plugin.includeTestSourceDirectory>true
103103
</maven-checkstyle-plugin.includeTestSourceDirectory>
104+
<jspecify.enabled>true</jspecify.enabled>
104105
</properties>
105106

106107
<modules>

spring-cloud-kubernetes-client-autoconfig/src/main/java/org/springframework/cloud/kubernetes/client/KubernetesClientPodUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.kubernetes.client.openapi.apis.CoreV1Api;
2424
import io.kubernetes.client.openapi.models.V1Pod;
2525
import io.kubernetes.client.util.Config;
26+
import org.jspecify.annotations.Nullable;
2627
import org.apache.commons.logging.Log;
2728
import org.apache.commons.logging.LogFactory;
2829

@@ -75,7 +76,7 @@ public boolean isInsideKubernetes() {
7576
return currentPod().get() != null;
7677
}
7778

78-
private V1Pod internalGetPod() {
79+
private @Nullable V1Pod internalGetPod() {
7980
try {
8081
if (isServiceHostEnvVarPresent() && isHostNameEnvVarPresent() && isServiceAccountFound()) {
8182
LOG.debug("reading pod in namespace : " + namespace);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2013-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Spring Cloud Kubernetes client config implementations.
19+
*/
20+
@org.jspecify.annotations.NullMarked
21+
package org.springframework.cloud.kubernetes.client.config;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2013-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Spring Cloud Kubernetes client discovery implementations.
19+
*/
20+
@org.jspecify.annotations.NullMarked
21+
package org.springframework.cloud.kubernetes.client.discovery;

spring-cloud-kubernetes-client-loadbalancer/src/main/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServiceInstanceMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.kubernetes.client.openapi.models.V1Service;
2626
import io.kubernetes.client.openapi.models.V1ServicePort;
2727
import io.kubernetes.client.openapi.models.V1ServiceSpec;
28+
import org.jspecify.annotations.Nullable;
2829
import org.apache.commons.logging.LogFactory;
2930

3031
import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance;
@@ -71,7 +72,7 @@ public KubernetesClientServiceInstanceMapper(KubernetesLoadBalancerProperties pr
7172
}
7273

7374
@Override
74-
public KubernetesServiceInstance map(V1Service service) {
75+
public @Nullable KubernetesServiceInstance map(V1Service service) {
7576
V1ObjectMeta metadata = service.getMetadata();
7677

7778
List<V1ServicePort> ports = ofNullable(service.getSpec()).map(V1ServiceSpec::getPorts).orElse(List.of());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2013-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Spring Cloud Kubernetes client load balancer implementations.
19+
*/
20+
@org.jspecify.annotations.NullMarked
21+
package org.springframework.cloud.kubernetes.client.loadbalancer;

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/KubernetesNamespaceProvider.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.nio.file.Path;
2222
import java.nio.file.Paths;
2323

24+
import org.jspecify.annotations.Nullable;
2425
import org.springframework.boot.context.properties.bind.BindHandler;
2526
import org.springframework.boot.context.properties.bind.Bindable;
2627
import org.springframework.boot.context.properties.bind.Binder;
@@ -71,7 +72,7 @@ public KubernetesNamespaceProvider(String namespacePropertyValue) {
7172
this.namespacePropertyValue = namespacePropertyValue;
7273
}
7374

74-
public static String getNamespaceFromServiceAccountFile(String path) {
75+
public static @Nullable String getNamespaceFromServiceAccountFile(String path) {
7576
String namespace = null;
7677
LOG.debug("Looking for service account namespace at: [" + path + "].");
7778
Path serviceAccountNamespacePath = Paths.get(path);
@@ -91,7 +92,7 @@ public static String getNamespaceFromServiceAccountFile(String path) {
9192
return namespace;
9293
}
9394

94-
public String getNamespace() {
95+
public @Nullable String getNamespace() {
9596
// If they provided the namespace in the constructor just return that
9697
if (!ObjectUtils.isEmpty(namespacePropertyValue)) {
9798
return namespacePropertyValue;
@@ -107,7 +108,7 @@ public String getNamespace() {
107108
return namespace != null ? namespace : getServiceAccountNamespace();
108109
}
109110

110-
private String getServiceAccountNamespace() {
111+
private @Nullable String getServiceAccountNamespace() {
111112
String serviceAccountNamespacePathString = null;
112113
if (environment != null) {
113114
serviceAccountNamespacePathString = environment.getProperty(NAMESPACE_PATH_PROPERTY,

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/CommonPropertySourceLocator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Locale;
2323
import java.util.Set;
2424

25+
import org.jspecify.annotations.Nullable;
2526
import org.apache.commons.logging.LogFactory;
2627

2728
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
@@ -52,7 +53,7 @@ protected abstract MapPropertySource getPropertySource(ConfigurableEnvironment e
5253
NormalizedSource normalizedSource, ReadType readType);
5354

5455
@Override
55-
public PropertySource<?> locate(Environment environment) {
56+
public @Nullable PropertySource<?> locate(Environment environment) {
5657

5758
if (environment instanceof ConfigurableEnvironment env) {
5859

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ProfileActivationAwareYamlPropertiesFactoryBean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import java.util.Properties;
2929
import java.util.stream.Collectors;
3030

31-
import jakarta.annotation.Nullable;
31+
import org.jspecify.annotations.Nullable;
3232
import org.apache.commons.logging.LogFactory;
3333
import org.yaml.snakeyaml.Yaml;
3434
import org.yaml.snakeyaml.reader.UnicodeReader;

0 commit comments

Comments
 (0)