Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException on startup #1831

Open
davgia opened this issue Jan 12, 2025 · 3 comments
Open

NullPointerException on startup #1831

davgia opened this issue Jan 12, 2025 · 3 comments
Labels

Comments

@davgia
Copy link

davgia commented Jan 12, 2025

Describe the bug
I have updated my java microservices (Java 17, Boot: 3.1.0, Cloud: 2022.0.2) to the latest available version of Spring Boot (3.4.1) and Spring Cloud (2024.0.0) and to Java 21. The spring application works fine locally and with my docker-compose test configuration. Deployed on Kubernetes it fails to startup with the following error:

12:07:07.633 [main] ERROR org.springframework.boot.SpringApplication -- Application run failed
java.lang.NullPointerException: Cannot invoke "org.springframework.cloud.kubernetes.commons.KubernetesClientProperties.withNamespace(String)" because the return value of "org.springframework.boot.ConfigurableBootstrapContext.get(java.lang.Class)" is null
    at org.springframework.cloud.kubernetes.commons.config.KubernetesConfigDataLocationResolver$PropertyHolder.clientProperties(KubernetesConfigDataLocationResolver.java:181)
    at org.springframework.cloud.kubernetes.commons.config.KubernetesConfigDataLocationResolver$PropertyHolder.of(KubernetesConfigDataLocationResolver.java:167)
    at org.springframework.cloud.kubernetes.commons.config.KubernetesConfigDataLocationResolver.resolveProfileSpecific(KubernetesConfigDataLocationResolver.java:89)
    at org.springframework.boot.context.config.ConfigDataLocationResolvers.lambda$resolve$2(ConfigDataLocationResolvers.java:107)
    at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:113)
    at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:106)
    at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:94)
    at org.springframework.boot.context.config.ConfigDataImporter.resolve(ConfigDataImporter.java:106)
    at org.springframework.boot.context.config.ConfigDataImporter.resolve(ConfigDataImporter.java:98)
    at org.springframework.boot.context.config.ConfigDataImporter.resolveAndLoad(ConfigDataImporter.java:86)
    at org.springframework.boot.context.config.ConfigDataEnvironmentContributors.withProcessedImports(ConfigDataEnvironmentContributors.java:121)
    at org.springframework.boot.context.config.ConfigDataEnvironment.processWithProfiles(ConfigDataEnvironment.java:316)
    at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:237)
    at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:96)
    at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:89)
    at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:132)
    at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:115)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
    at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81)
    at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64)
    at java.base/java.lang.Iterable.forEach(Iterable.java:75)
    at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118)
    at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:353)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350)
    at com.example.demo.DemoApplication.main(DemoApplication.java:10)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:102)
    at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:64)
    at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:40)

Sample
This is a sample of a spring cloud gateway webflux application. I've included both Dockerfile and k8s manifests to test it.

demo.zip

Linked issues
This issues it is probably related to #1654.

@davgia davgia changed the title [BUG] Cannot invoke "org.springframework.cloud.kubernetes.commons.KubernetesClientProperties.withNamespace(String)" because the return value of "org.springframework.boot.ConfigurableBootstrapContext.get(java.lang.Class)" is null [BUG] NullPointerException retrieving org.springframework.boot.ConfigurableBootstrapContext.get(java.lang.Class) on startup Jan 12, 2025
@davgia davgia changed the title [BUG] NullPointerException retrieving org.springframework.boot.ConfigurableBootstrapContext.get(java.lang.Class) on startup [BUG] NullPointerException on startup Jan 12, 2025
@davgia davgia changed the title [BUG] NullPointerException on startup NullPointerException on startup Jan 12, 2025
@wind57
Copy link
Contributor

wind57 commented Jan 31, 2025

it's a bug, thank you for your report. Its very similar indeed to the linked one.

@ryanjbaxter can you add the bug label please? I will see how to fix it..

@ryanjbaxter
Copy link
Contributor

I was litterally just looking at this issue :). Seems like you were just ahead of me

@wind57
Copy link
Contributor

wind57 commented Jan 31, 2025

yeah, its the same dependency thing we had in the past in the linked issue. In Fabric8ConfigServerBootstrapper we do :

		registry.registerIfAbsent(KubernetesClientProperties.class, context -> {
			if (!getDiscoveryEnabled(context)) {
				return null;
			}
			return createKubernetesClientProperties(context);
		});

so we register a "null" but later try to do something with that one. I will take a look closer on it in the upcoming days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants