[DATACMNS-1245] Consider Kotlin metadata annotation for Kotlin class kind retrieval Created: 17/Jan/18  Updated: 24/Jan/18  Resolved: 19/Jan/18

Status: Closed
Project: Spring Data Commons
Component/s: None
Affects Version/s: 2.0.2 (Kay SR2)
Fix Version/s: 2.1 M1 (Lovelace), 2.0.3 (Kay SR3)

Type: Task Priority: Major
Reporter: Juergen Zimmermann Assignee: Mark Paluch
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10, JDK 9.0.4, Kotlin 1.2.20, Spring Data Kay-SR2


Attachments: File DbConfig.kt     File DbReactiveConfig.kt    
Last updater: Mark Paluch
Pull Request URL: https://github.com/spring-projects/spring-data-commons/pull/269

 Description   

After upgrading from Kotlin 1.2.10 to 1.2.20 I'm getting the error log below. My own class DbConfig (because of TLS connection w/ MongoDB) is derived from org.springframework.data.mongodb.config.AbstractMongoConfiguration, and just inherits mappingMongoConverter() which invokes org.springframework.data.mongodb.config.MongoConfigurationSupport.mongoMappingContext(). I'll attach my own files DbConfig.kt and DbReactiveConfig.kt.

The error log:

2018-01-17 13:16:14.518 WARN 16544 — [ restartedMain] onfigReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start reactive web server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'httpHandler' defined in class path resource [org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfiguration$AnnotationConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.http.server.reactive.HttpHandler]: Factory method 'httpHandler' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration$EnableWebFluxConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.reactive.ServerHttpSecurityConfiguration': Unsatisfied dependency expressed through field 'reactiveUserDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customUserDetailsService' defined in file [C:\Users\ziju0001\IdeaProjects\kunde\build\classes\kotlin\main\de\hska\kunde\config\security\CustomUserDetailsService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customUserDetailsRepository': Cannot resolve reference to bean 'reactiveMongoTemplate' while setting bean property 'reactiveMongoOperations'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reactiveMongoTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoReactiveDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'reactiveMongoTemplate' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingMongoConverter' defined in class path resource [de/hska/kunde/config/DbReactiveConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.convert.MappingMongoConverter]: Factory method 'mappingMongoConverter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext' defined in class path resource [de/hska/kunde/config/DbConfig.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: kotlin/reflect/jvm/internal/impl/load/kotlin/reflect/ReflectKotlinClass



 Comments   
Comment by Mark Paluch [ 17/Jan/18 ]

We're using Kotlin internals to determine whether a particular class type is supported or not. In particular, we only support regular classes (no facades/SAM classes/multi-file classes). This check is required as unsupported classes cause exceptions within Kotlin libraries so we're basically guarding all code from Kotlin bugs.

Kotlin changed its internals and moved around packages.

Comment by Mark Paluch [ 17/Jan/18 ]

Moved to Spring Data Commons and changed this ticket to a task adopting to Kotlin 1.2.20

Comment by Mark Paluch [ 17/Jan/18 ]

I pushed a change to the DATACMNS-1245 branch that picks up Kotlin's changes. Care to give 2.1.0.DATACMNS-1245-SNAPSHOT a spin?

<dependency>
  <groupId>org.springframework.data</groupId>
  <artifactId>spring-data-commons</artifactId>
  <version>2.1.0.DATACMNS-1245-SNAPSHOT</version>
</dependency>

<repository>
  <id>spring-libs-snapshot</id>
  <name>Spring Snapshot Repository</name>
  <url>http://repo.spring.io/libs-snapshot</url>
</repository>
Comment by Juergen Zimmermann [ 17/Jan/18 ]

The issue is gone after I added org.springframework.data:spring-data-commons:2.1.0.DATACMNS-1245-SNAPSHOT in build.gradle.

Comment by Mark Paluch [ 19/Jan/18 ]

Changed the pull request to evaluate Kotlin's `@Metadata` annotation after feedback from Jetbrains.

Comment by Juergen Zimmermann [ 19/Jan/18 ]

@mp911de What is the implication after your PR is declined? Can I test something different?

Comment by Mark Paluch [ 19/Jan/18 ]

No worries, the PR isn't declined, the code is merged. GitHub expects the same commit hash in the target branch to consider a pull request merged. We use cherry-picking to bring our commits from a feature branch into master and service-release branches. That said, you can use 2.0.3 and 2.1.0 snapshots that already contain the fix.

Generated at Fri Nov 15 02:00:54 UTC 2019 using Jira 7.13.8#713008-sha1:1606a5c1e7006e1ab135aac81f7a9566b2dbc3a6.