centrifugal / centrifuge-java

General Java and Android client SDK for bidirectional communication with Centrifugo and Centrifuge-based server over WebSocket
MIT License
65 stars 33 forks source link

And nullable/nonnullable annotation to improve Kotlin API #54

Closed PhilipDukhov closed 1 year ago

PhilipDukhov commented 1 year ago

Right now, when used from Kotlin, library generates a lot of optional parameters - that's default behaviour for Java interop, as there's no build-in nullability checks.

object : SubscriptionEventListener() {
    override fun onSubscribed(sub: Subscription?, event: SubscribedEvent?) {
    }

With this PR I've added ParametersAreNonnullByDefault annotation to the lib package - this makes all arguments non nullable by default for IDEA linter and for Kotlin interop.

Also I've added a couple Nullable annotation for parameters that actually can be null - after adding @ParametersAreNonnullByDefault, IDEA showed me such places with warnings.

Also fixed a couple of warned placed

FZambia commented 1 year ago

@PhilipDukhov many thanks, I'll go through the changes one more time very soon and if no other comments will appear proceed with merging.

FZambia commented 1 year ago

Awesome 👍

FZambia commented 1 year ago

@PhilipDukhov hello, unfortunately I think this requires more careful research. I just noticed that all my Java code that uses this SDK started to have various warnings like this:

Screenshot 2023-02-14 at 23 44 57

Also it started complaining to possible NullPointerException where it can't be thrown:

Screenshot 2023-02-14 at 23 54 59

I see more clearly now how Result type may help here 😬

Not sure this all can be fixed quickly. Seems that I'll have to revert the change for now :(

FZambia commented 1 year ago

Opened https://github.com/centrifugal/centrifuge-java/issues/61