Skip to content

Commit 31d18eb

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

File tree

29 files changed

+292
-19
lines changed

29 files changed

+292
-19
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
@@ -25,6 +25,7 @@
2525
import io.kubernetes.client.util.Config;
2626
import org.apache.commons.logging.Log;
2727
import org.apache.commons.logging.LogFactory;
28+
import org.jspecify.annotations.Nullable;
2829

2930
import org.springframework.cloud.kubernetes.commons.EnvReader;
3031
import org.springframework.cloud.kubernetes.commons.LazilyInstantiate;
@@ -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
@@ -26,6 +26,7 @@
2626
import io.kubernetes.client.openapi.models.V1ServicePort;
2727
import io.kubernetes.client.openapi.models.V1ServiceSpec;
2828
import org.apache.commons.logging.LogFactory;
29+
import org.jspecify.annotations.Nullable;
2930

3031
import org.springframework.cloud.kubernetes.commons.discovery.DefaultKubernetesServiceInstance;
3132
import org.springframework.cloud.kubernetes.commons.discovery.DiscoveryClientUtils;
@@ -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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.nio.file.Path;
2222
import java.nio.file.Paths;
2323

24+
import org.jspecify.annotations.Nullable;
25+
2426
import org.springframework.boot.context.properties.bind.BindHandler;
2527
import org.springframework.boot.context.properties.bind.Bindable;
2628
import org.springframework.boot.context.properties.bind.Binder;
@@ -71,7 +73,7 @@ public KubernetesNamespaceProvider(String namespacePropertyValue) {
7173
this.namespacePropertyValue = namespacePropertyValue;
7274
}
7375

74-
public static String getNamespaceFromServiceAccountFile(String path) {
76+
public static @Nullable String getNamespaceFromServiceAccountFile(String path) {
7577
String namespace = null;
7678
LOG.debug("Looking for service account namespace at: [" + path + "].");
7779
Path serviceAccountNamespacePath = Paths.get(path);
@@ -91,7 +93,7 @@ public static String getNamespaceFromServiceAccountFile(String path) {
9193
return namespace;
9294
}
9395

94-
public String getNamespace() {
96+
public @Nullable String getNamespace() {
9597
// If they provided the namespace in the constructor just return that
9698
if (!ObjectUtils.isEmpty(namespacePropertyValue)) {
9799
return namespacePropertyValue;
@@ -107,7 +109,7 @@ public String getNamespace() {
107109
return namespace != null ? namespace : getServiceAccountNamespace();
108110
}
109111

110-
private String getServiceAccountNamespace() {
112+
private @Nullable String getServiceAccountNamespace() {
111113
String serviceAccountNamespacePathString = null;
112114
if (environment != null) {
113115
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
@@ -23,6 +23,7 @@
2323
import java.util.Set;
2424

2525
import org.apache.commons.logging.LogFactory;
26+
import org.jspecify.annotations.Nullable;
2627

2728
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
2829
import org.springframework.core.env.CompositePropertySource;
@@ -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,8 +28,8 @@
2828
import java.util.Properties;
2929
import java.util.stream.Collectors;
3030

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

0 commit comments

Comments
 (0)