spring-attic / spring-native

Spring Native is now superseded by Spring Boot 3 official native support
https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html
Apache License 2.0
2.74k stars 355 forks source link

Kotlin coroutine with R2DBC Postress not found DataIntegrityViolationException under @ControllerAdvice #1563

Closed mmuniz75 closed 2 years ago

mmuniz75 commented 2 years ago

I have a Kotlin coroutine with R2DBC Postresql's app, and when I throw a business exception , a @ControllerAdvice class intercept the error and throws :

java.lang.ClassNotFoundException: org.springframework.dao.DataIntegrityViolationException askalien-admin_1 | at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:54) ~[na:na] askalien-admin_1 | Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: askalien-admin_1 | Error has been observed at the following site(s): askalien-admin_1 | *__checkpoint ? HTTP PUT "/aquarium/fish" [ExceptionHandlingWebHandler] askalien-admin_1 | Original Stack Trace: askalien-admin_1 | at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:54) ~[na:na] askalien-admin_1 | at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na]

I am not thowing a DataIntegrityViolationException in @ControllerAdvice it is just in the class.

versions

Spring native : 0.11.3 Spring Boot : 2.6.4 Kotlin : 1.6.10 Java : 11

mhalbritter commented 2 years ago

If you'd like us to spend some time investigating, please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

mmuniz75 commented 2 years ago

Hi,

I have the project under https://github.com/mmuniz75/aquario, but I need create a branch version point to H2 and populate the data.

I am going to create it and send to you

thanks


From: Moritz Halbritter @.> Sent: Thursday, March 31, 2022 12:26 PM To: spring-projects-experimental/spring-native @.> Cc: Marcelo Muniz Silva @.>; Author @.> Subject: Re: [spring-projects-experimental/spring-native] Kotlin coroutine with R2DBC Postress not found DataIntegrityViolationException under @ControllerAdvice (Issue #1563)

If you'd like us to spend some time investigating, please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

— Reply to this email directly, view it on GitHubhttps://github.com/spring-projects-experimental/spring-native/issues/1563#issuecomment-1084513909, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFNYYZAFPOUO2NVKSRMAN73VCWKWLANCNFSM5SEYFQKQ. You are receiving this because you authored the thread.Message ID: @.***>

mmuniz75 commented 2 years ago

The project to reproduce the error is here : https://github.com/mmuniz75/aquario/tree/h2

Just need call the following curl :

curl --location --request PUT 'http://localhost:8080/aquarium/fish' \ --header 'Content-Type: application/json' \ --data-raw '{ "fishId" : 4, "fishCount" : 10, "centimetersAvailable" : 32, "currentFishIds" : [37,43,56, 22] }'

The Coroutine code throw a PreConditionException and the Controller Advice GlobalExceptionHandler throw the exception :

java.lang.ClassNotFoundException: org.springframework.dao.DataIntegrityViolationException askalien-admin_1 | at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:54) ~[na:na] askalien-admin_1 | Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: askalien-admin_1 | Error has been observed at the following site(s): askalien-admin_1 | *__checkpoint ? HTTP PUT "/aquarium/fish" [ExceptionHandlingWebHandler] askalien-admin_1 | Original Stack Trace: askalien-admin_1 | at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:54) ~[na:na] askalien-admin_1 | at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na] askalien-admin_1 | at java.lang.ClassLoader.loadClass(ClassLoader.java:141) ~[na:na] askalien-admin_1 | at kotlin.reflect.jvm.internal.KDeclarationContainerImpl.parseType(KDeclarationContainerImpl.kt:265) ~[na:na] askalien-admin_1 | at kotlin.reflect.jvm.internal.KDeclarationContainerImpl.loadParameterTypes(KDeclarationContainerImpl.kt:256) ~[na:na] askalien-admin_1 | at kotlin.reflect.jvm.internal.KDeclarationContainerImpl.findMethodBySignature(KDeclarationContainerImpl.kt:197) ~[na:na] askalien-admin_1 | at kotlin.reflect.jvm.internal.KFunctionImpl$caller$2.invoke(KFunctionImpl.kt:68) ~[na:na] askalien-admin_1 | at kotlin.reflect.jvm.internal.KFunctionImpl$caller$2.invoke(KFunctionImpl.kt:61) ~[na:na] askalien-admin_1 | at kotlin.reflect.jvm.internal.ReflectProperties$LazyVal.invoke(ReflectProperties.java:63) ~[na:na] askalien-admin_1 | at kotlin.reflect.jvm.internal.ReflectProperties$Val.getValue(ReflectProperties.java:32) ~[na:na] askalien-admin_1 | at kotlin.reflect.jvm.internal.KFunctionImpl.getCaller(KFunctionImpl.kt:61) ~[na:na] askalien-admin_1 | at kotlin.reflect.jvm.ReflectJvmMapping.getJavaMethod(ReflectJvmMapping.kt:63) ~[na:na] askalien-admin_1 | at kotlin.reflect.jvm.ReflectJvmMapping.getKotlinFunction(ReflectJvmMapping.kt:136) ~[na:na] askalien-admin_1 | at org.springframework.core.MethodParameter$KotlinDelegate.getReturnType(MethodParameter.java:932) ~[na:na] askalien-admin_1 | at org.springframework.core.MethodParameter$KotlinDelegate.access$100(MethodParameter.java:866) ~[na:na] askalien-admin_1 | at org.springframework.core.MethodParameter.computeParameterType(MethodParameter.java:538) ~[na:na] askalien-admin_1 | at org.springframework.core.MethodParameter.getParameterType(MethodParameter.java:492) ~[na:na]

mhalbritter commented 2 years ago

Hello,

can't reproduce this issue. I started postgres in docker, wired the r2dbc URL in the application.yml and started the application. Then i executed your curl. I see no exceptions in the log.

It looks like that the schema is missing?

io.r2dbc.postgresql.ExceptionFactory$PostgresqlBadGrammarException: [42P01] relation "fish" does not exist
mmuniz75 commented 2 years ago

please use this branch with h2 that has all data https://github.com/mmuniz75/aquario/tree/h2

curl to test : curl --location --request PUT 'http://localhost:8080/aquarium/fish' --header 'Content-Type: application/json' --data-raw '{ "fishId" : 4, "fishCount" : 10, "centimetersAvailable" : 32, "currentFishIds" : [37,43,56, 22] }'

mhalbritter commented 2 years ago

Ah, thanks. I didn't use the h2 branch. I can now reproduce the issue. This happens when using GraalVM 22.0. The issue is gone when using the newest dev build for GraalVM 22.1.

curl --location --request PUT 'http://localhost:8080/aquarium/fish' --header 'Content-Type: application/json' --data-raw '{ "fishId" : 4, "fishCount" : 10, "centimetersAvailable" : 32, "currentFishIds" : [37,43,56, 22] }'
mhalbritter commented 2 years ago

This is an issue on GraalVM side. We will switch to 22.1 as soon as it is released. In the meantime, you can workaround this by using the newest dev build

mmuniz75 commented 2 years ago

Where can I set on pom to use GraalVM 22.1 ?


From: Moritz Halbritter @.> Sent: Wednesday, April 6, 2022 6:39 AM To: spring-projects-experimental/spring-native @.> Cc: Marcelo Muniz Silva @.>; Author @.> Subject: Re: [spring-projects-experimental/spring-native] Kotlin coroutine with R2DBC Postress not found DataIntegrityViolationException under @ControllerAdvice (Issue #1563)

This is an issue on GraalVM side. We will switch to 22.1 as soon as it is released. In the meantime, you can workaround this by using the newest dev buildhttps://github.com/graalvm/graalvm-ce-dev-builds/releases/tag/22.1.0-dev-20220404_0905

— Reply to this email directly, view it on GitHubhttps://github.com/spring-projects-experimental/spring-native/issues/1563#issuecomment-1089878732, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFNYYZGO6DFAIGFMGSAV3WTVDUWT5ANCNFSM5SEYFQKQ. You are receiving this because you authored the thread.Message ID: @.***>

mhalbritter commented 2 years ago

It depends how you build the application. i use sdkman, have downloaded the graalVM 21.1-dev from their github releases and installed it as a local version.

mmuniz75 commented 2 years ago

I just run : mvn spring-boot:build-image


From: Moritz Halbritter @.> Sent: Thursday, April 7, 2022 7:03 AM To: spring-projects-experimental/spring-native @.> Cc: Marcelo Muniz Silva @.>; Author @.> Subject: Re: [spring-projects-experimental/spring-native] Kotlin coroutine with R2DBC Postress not found DataIntegrityViolationException under @ControllerAdvice (Issue #1563)

It depends how you build the application. i use sdkmanhttps://sdkman.io/, have downloaded the graalVM 21.1-dev from their github releases and installed it as a local versionhttps://sdkman.io/usage#localversion.

— Reply to this email directly, view it on GitHubhttps://github.com/spring-projects-experimental/spring-native/issues/1563#issuecomment-1091152374, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFNYYZDDXNYXZKATRV4TWN3VD2CDFANCNFSM5SEYFQKQ. You are receiving this because you authored the thread.Message ID: @.***>

mhalbritter commented 2 years ago

This uses the buildpacks. There's a way to change the Graal version, see this documentation. I'm not sure if buildpacks allow using Graal 22.1 dev yet. If not, use the sdkman workaround I shared until a stable 22.1 is released. There's nothing we can do on spring-native side here.