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

Native support for RetryTemplateFactory as it uses reflections to access the field logger of RetryTemplate #2439

Closed
klopfdreh opened this issue Jul 10, 2024 · 8 comments · Fixed by #2456
Assignees
Labels
Milestone

Comments

@klopfdreh
Copy link
Contributor

Describe the bug
We wanted to use Spring Cloud Config Client within a native image. During the startup of our application we saw a NullPointerException

java.lang.NullPointerException
at org.springframework.cloud.config.client.RetryTemplateFactory.create(RetryTemplateFactory.java:47)
at org.springframework.cloud.config.client.ConfigClientRetryBootstrapper.lambda$initialize$1(ConfigClientRetryBootstrapper.java:46)
at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.load(ConfigServerConfigDataLoader.java:92)
at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.load(ConfigServerConfigDataLoader.java:61)
at org.springframework.boot.context.config.ConfigDataLoaders.load(ConfigDataLoaders.java:96)

We had a look into RetryTemplateFactory and saw field = ReflectionUtils.findField(RetryTemplate.class, "logger"); in line 31 and field.set(retryTemplate, log); in line 47.

There is no reflect-config.json provided to describe this access.

Sample
N/A

@AlexGreg
Copy link

same for me..I solved it by adding to reflect-config.json

[
  {
    "name": "org.springframework.retry.support.RetryTemplate",
    "allDeclaredFields": true,
    "allDeclaredMethods": true,
    "allDeclaredConstructors": true
  },
  {
    "name": "org.springframework.cloud.config.client.RetryTemplateFactory",
    "allDeclaredMethods": true,
    "allDeclaredConstructors": true
  }
]

@klopfdreh
Copy link
Contributor Author

klopfdreh commented Jul 26, 2024

Hey @AlexGreg

thanks that you also commented this issue!

Exactly this needs to be provided by spring-cloud-config-client 👍

Edit: As this is a Spring Boot project the existing RuntimeHintsRegistrar can be used to apply those reflection hints.

@klopfdreh
Copy link
Contributor Author

@ryanjbaxter - should we do it this way or should I provide a RuntimeHintsRegistrar and apply the hints that way?

@klopfdreh
Copy link
Contributor Author

@ryanjbaxter - I made a suggestion as this is a Spring Project I guess we are safe to use a RuntimeHintsRegistrar. See the PR for more information, please.

@klopfdreh
Copy link
Contributor Author

klopfdreh commented Sep 14, 2024

@OlgaMaciaszek / @ryanjbaxter - sorry that I ask you directly for assistance, again. We are currently using Spring Cloud Config with Spring Retry and without the changes I suggested at Spring Cloud Config Client it can’t be used within a Spring Boot Native image without defining additional reflect definitions.

The changes are rather small and I only moved an existing class to its own file and added reflection hints to classes mentioned in this issue.

I would be very grateful if you could review those changes and may include them in one of the next releases.

@OlgaMaciaszek
Copy link
Contributor

Hi @klopfdreh Thanks for reporting the issue. Will fix it shortly.

@klopfdreh
Copy link
Contributor Author

@OlgaMaciaszek I fixed it already - just review and merge if everything is fine for you: #2456

@OlgaMaciaszek
Copy link
Contributor

Thanks @klopfdreh - done.

@OlgaMaciaszek OlgaMaciaszek moved this to In Progress in 2023.0.4 Sep 16, 2024
@OlgaMaciaszek OlgaMaciaszek moved this to In Progress in 2024.0.0-M2 Sep 16, 2024
@OlgaMaciaszek OlgaMaciaszek added this to the 4.1.4 milestone Sep 16, 2024
@OlgaMaciaszek OlgaMaciaszek moved this from In Progress to Done in 2023.0.4 Sep 16, 2024
@OlgaMaciaszek OlgaMaciaszek moved this from In Progress to Done in 2024.0.0-M2 Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants