spring-modulith
spring-modulith copied to clipboard
spring-modulith-observability causes Kotlin bean properties to be initialized as null
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-observabilityis enabled, the properties in the Kotlin bean arenullas seen in the following screenshots.
Screenshots:
-
Bean initialization with
nullvalues: -
CGLIB proxy details showing
nullfor constructor-injected properties:
The version used is 1.2.3
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?
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
nullfields in the debugger?
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?
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?
$ 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?
$ 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 executedHow do I reproduce the problem?
Start the application and visit http://127.0.0.1:8080 to see the exception in the console.
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.
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
For the former command, I get:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':core:bootRun'.
> Failed to calculate the value of task ':core:bootRun' property 'mainClass'.
> Main class name has not been configured and it could not be resolved from classpath /Users/odrotbohm/temp/spring-modulith-test/core/build/classes/kotlin/main
For the latter:
FAILURE: Build failed with an exception.
* What went wrong:
Cannot locate tasks that match ':app' as task 'app' not found in root project 'spring-modulith-test'.
For the former command, I get:
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':core:bootRun'. > Failed to calculate the value of task ':core:bootRun' property 'mainClass'. > Main class name has not been configured and it could not be resolved from classpath /Users/odrotbohm/temp/spring-modulith-test/core/build/classes/kotlin/mainFor the latter:
FAILURE: Build failed with an exception. * What went wrong: Cannot locate tasks that match ':app' as task 'app' not found in root project 'spring-modulith-test'.
My mistake, I should have used ./gradlew :app:bootRun