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

spring-modulith-observability causes Kotlin bean properties to be initialized as null #800

Open
chenzhenjia opened this issue Sep 5, 2024 · 9 comments
Assignees
Labels
in: observability Observability support meta: waiting for feedback Waiting for feedback of the original reporter

Comments

@chenzhenjia
Copy link

When enabling spring-modulith-observability, Kotlin bean properties are unexpectedly initialized as null. For example, after enabling this module, properties such as hisHttpClient and medicalInstitutionCode are null. Disabling the module resolves the problem.

Expected behavior:

  • Kotlin bean properties should be correctly initialized when observability is enabled.

Actual behavior:

  • When spring-modulith-observability is enabled, the properties in the Kotlin bean are null as seen in the following screenshots.

Screenshots:

  1. Bean initialization with null values:
image
  1. CGLIB proxy details showing null for constructor-injected properties:
image
@chenzhenjia
Copy link
Author

The version used is 1.2.3
image

@odrotbohm
Copy link
Member

That's not unexpected regarding the class that you see being a proxy whose actual target will still have the proper dependencies wired. This should only be a problem if you try to access the fields directly. Method invocations, however, will pass the interceptor chain and ultimately trigger the method invocation on the target.

Can you clarify how a problem manifests from that, beyond you seeing the null fields in the debugger?

@odrotbohm odrotbohm self-assigned this Sep 12, 2024
@odrotbohm odrotbohm added in: observability Observability support meta: waiting for feedback Waiting for feedback of the original reporter labels Sep 12, 2024
@chenzhenjia
Copy link
Author

Snipaste_2024-09-13_09-07-42
java.lang.NullPointerException: Parameter specified as non-null is null: method reqeust.MedicalInfoRequest.<init>, parameter medicalInstitutionCode

That's not unexpected regarding the class that you see being a proxy whose actual target will still have the proper dependencies wired. This should only be a problem if you try to access the fields directly. Method invocations, however, will pass the interceptor chain and ultimately trigger the method invocation on the target.

Can you clarify how a problem manifests from that, beyond you seeing the null fields in the debugger?

@odrotbohm
Copy link
Member

Unfortunately few line screenshots are not that helpful in diagnosing the problem. Is there any chance you provide a minimal reproducer? Is anyone trying to access the field directly instead of calling a method passing the proxy?

@chenzhenjia
Copy link
Author

chenzhenjia commented Sep 16, 2024

Unfortunately few line screenshots are not that helpful in diagnosing the problem. Is there any chance you provide a minimal reproducer? Is anyone trying to access the field directly instead of calling a method passing the proxy?

test project

spring-modulith-test-main.zip

@odrotbohm
Copy link
Member

$ git clone https://github.com/chenzhenjia/spring-modulith-test
$ cd spring-modulith-test
$ chmod +x ./gradlew
$ ./gradlew
BUILD SUCCESSFUL in 1m 30s
1 actionable task: 1 executed

How do I reproduce the problem?

@chenzhenjia
Copy link
Author


$ git clone https://github.com/chenzhenjia/spring-modulith-test

$ cd spring-modulith-test

$ chmod +x ./gradlew

$ ./gradlew

BUILD SUCCESSFUL in 1m 30s

1 actionable task: 1 executed

How do I reproduce the problem?

Start the application and visit http://127.0.0.1:8080 to see the exception in the console.

@odrotbohm
Copy link
Member

I am sorry, but I won't follow up unless you can properly prepare the project, including instructions what to do with the code to see the problem (what does "start the application" mean?). I ran the project (./gradlew). It leads to a successful build.

@chenzhenjia
Copy link
Author

I am sorry, but I won't follow up unless you can properly prepare the project, including instructions what to do with the code to see the problem (what does "start the application" mean?). I ran the project (./gradlew). It leads to a successful build.

Try ./gradlew bootRun or ./gradlew :app bootRun to start the spring boot application

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: observability Observability support meta: waiting for feedback Waiting for feedback of the original reporter
Projects
None yet
Development

No branches or pull requests

2 participants