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

More "Kotlin Gotchas" with abstract classes #1268

Closed
lathspell opened this issue Dec 6, 2022 · 2 comments
Closed

More "Kotlin Gotchas" with abstract classes #1268

lathspell opened this issue Dec 6, 2022 · 2 comments

Comments

@lathspell
Copy link

I have some trouble with the ShedLock 4.43.0 in combination with Kotlin 1.7.22 and SpringBoot 2.7.6 (all latest versions) and JRE 11. The description in "Kotlin gotchas" in the documentation says "If @scheduled annotation is not present, you have to open the method by yourself." - In my case the annotation was present but I still had to open the methods manually. This was necessary because the methods were in an "abstract class" but the @scheduled in the derived class.

Maybe it's worth mentioning in the Gotchas section.

My example is in https://github.com/lathspell/spring_kotlin_abstract_bug and roughly:

  class Foo(something: Something): AbstractFoo(something) {
    @Scheduled...
    @SchedulerLock...
    fun cronjob() {...}
  }

  class AbstractFoo(private val something: Something) {
     fun save() { // here "something" is NULL although defined as not-nullable!
  }

Originally I wanted to report this as a but to the "kotlin-spring" or Kotlin "all-open" plugin but then I noticed that the problem
only occurs when using the @SchedulerLock annotation.

Can you elaborate why this breaks the Spring CGI-proxy stuff? Is there maybe something that ShedLock could do better?

It's pretty nasty when you have a working project, then add ShedLock and suddenly NullPointerExceptions turn up!

@lukas-krecan
Copy link
Owner

Hi, thanks for feedback. The reason is simple. @Scheduled does not require AOP, Spring just needs to call the method. For @SchedulerLock to work, you need AOP and Spring either has to generate a subclass or generate a proxy. I will try to update the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants