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
Add nullability annotations to jOOQ API for better Kotlin interop #6244
Comments
See licensing concerns here: #4748 (comment) |
Spring has moved forward with JSR 305 adoption through the
Let's wait how Spring fares with this strategy. I feel that we're really on a very wrong path as an ecosystem. If we cannot agree on something silly and stupid as a |
Kotlin added support for While I agree that this isn't the perfect solution, I think it would be great to have jOOQ annotate nullable and non-nullable types, even if it's with its own custom annotation. |
I rest my case (for now):
|
A lot of time has passed since this topic was first discussed. Support
|
Thanks for your comments, @fkowal. The usage of JSR 305 is crystal clear. The reservations mentioned in this issue and elsewhere aren't purely technical. JSR 305 still creates a legal mess. Is it LGPL licensed like FindBugs? Or BSD licensed as claimed on some websites? Or ASL 2.0 licensed as mentioned in the maven artifact Nothing seems to have changed since this issue was first created. Everyone is just hacking around, and I'm really reluctant to spend a lot of time annotating the entire jOOQ API with something that is so unclean - without any clear and obvious benefits, too! The Kotlin integration could profit from this, yes, but only to a limited extent, as Kotlin has made good choices to integrate with Java APIs by introducing So, this issue remains dormant, until it has been shown that either:
|
The lack of nullalbe annotations on things that can be null also leaves a lot to be desired when you're used to Kotlin warning you when you forgot to properly handle the null values. Every time I see If the JSR annotations have legal problems, why not use one of the alternatives? I agree it isn't ideal having to depend on a non "standard" library like |
Thanks for your suggestion, @xenomachina. Annotating each and every method is definitely not practical. JSR-305 has this |
Currently looking into this again as jOOQ 3.14 will offer many improvements for Kotlin users. Additional reservations in the area of JSR-305 are listed here: Including an important JPMS problem: https://blog.codefx.org/java/jsr-305-java-9 |
I will play around with the JetBrains annotations: https://www.jetbrains.com/help/idea/nullable-and-notnull-annotations.html |
I'm reopening this, because for the past weeks, this has been getting heavily on my nerves: This is a show stopper for the JetBrains annotations, if there's no way to turn off this feature in content-assist. Another library would still be possible, though. |
This is due to a number of things:
See: https://stackoverflow.com/a/63051248/521799 So, the workaround could be to turn on this feature, or upvote my suggested UX improvement by allowing to turn off auto-completing the generation of type annotations: https://bugs.eclipse.org/bugs/show_bug.cgi?id=565463 |
OK, I guess this is Eclipse's stance on the problem: Works as designed. I'll think about this again, and review if we should thus replace JetBrains annotations with something else, again. |
Making the Maven dependency optional/provided seems to resolve this UX issue in Eclipse: |
The dependency can be pulled in transitively, nonetheless: testcontainers/testcontainers-java#3057. A workaround would then be to do: <dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${org.testcontainers.version}</version>
<exclusions>
<exclusion>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
</exclusion>
</exclusions>
</dependency> |
Soo a group of us have been slowly working on an attempt to "fix" nullness annotations for JVM languages. Kotlin in particular is on-board. I've been working on better public-facing explanatory documentation for our site http://jspecify.org, but in the meantime thought I would at least mention here at this is going on and we'd be more than open to talking with your project about how to make sure our artifact would meet your needs. If interested in that conversation, how/where/with-whom would you like it to happen? (I'll keep working on making the site more self-explanatory.) |
😅 That's great news, thanks for chiming in @kevinb9n. So far, I'm quite happy with the results of having integrated the JetBrains annotations, which were a pragmatic choice here. But an improved (and finalised) JSR 305 could be even better, which is somewhat similar to what you're working on? The best solution would be a JEP, but I guess that's a ton of spec work, making success less probable.
Very interested! How I think that by writing in public is always good, to benefit future discoverability of the discussion (compared to phone calls, etc). Where This issue tracker is fine, though a new issue because this one here is already quite specific to 1) kotlin, 2) previous work. Your suggestions would be quite long term, and not necessarily kotlin specific. E.g. Scala 3 (to my pleasant surprise) went the Ceylon way and used union types to model nulls, and also supports a variety of popular annotations: https://dotty.epfl.ch/docs/reference/other-new-features/explicit-nulls.html Since jOOQ is also quite powerful and somewhat popular in Scala, I think it would be good to move your discussion to a new issue. Alternatively, I'll be happy to join discussions on your issue tracker. With-whom That would be me |
Thanks for the quick and detailed response!
done #12949 |
* chore(dependencies): Autobump korkVersion * fix(sql/test): keep up with API changes from jooq 3.13 to 3.14 See https://www.jooq.org/api-diff/3.13-3.14, jOOQ/jOOQ#6244 and jOOQ/jOOQ#10512. --------- Co-authored-by: root <root@2b5a6b05cb3f> Co-authored-by: David Byron <dbyron@salesforce.com>
While generating JSR-305 annotations is not technically correct (#4748) as a non-null column may be null "in transit" (e.g. when the constraint is deferred, or for a while in Java code, prior to storing the record, or when fetching a record from an outer join, which removes not null constraints) it might certainly make sense to annotate most jOOQ API with
@javax.annotation.Nonnull
and@javax.annotation.Nullable
. This would greatly improve the interoperability experience, especially for Kotlin / Ceylon users.Alternatives are possible, e.g. using the JetBrains annotations.
When annotating the API, the following things can be done automatically:
@Support
is also automatically@NotNull
. Exceptions:fetchOne()
fetchValue()
fetchSingle()
(if it takes aField<T>
argument and returnsT
)Stream
Optional
List
,Map
,Set
(there are a few exceptions, where the object corresponds to a record)X[]
CompletionStage
Some API will be left out of this improvement. This includes:
T
is@Nullable
Field
orCondition
, etc. is@NotNull
DSLContext.transactionResult()
@NotNull
is impliedIncompatible change
For Kotlin users, this will be an incompatible change as they will get occasional compilation errors, e.g. when using
fetchOne()
The text was updated successfully, but these errors were encountered: