8

Haha, fuck you kotlin! and your null safety!
I was able to break it 😆

After reading about its syntax for over 2 weeks , i finally sat down to write a simple parsing app completely in kotlin. And now i don't know how, but i am able to store a null in a "val x:String" (i.e a non null variable)

I am not going to claim it as some miracle or discovery as some other ranters, it might be a mistake. I am just a 21 yo Android/java dev trying to re write my old ,tested java code to kotlin by myself, without any auto convert, in the middle of night when i am 99% asleep by brain.

I will try to raise an SO question with details, but all i used was a simple volley request returning heterogeneous data, a gson convertor and a single activity,
Right now i am buzzing off to my sleep

Comments
  • 2
    tactical dot in case there's more exact info on how the fuck that is possible
  • 1
    My initial guess is something in that pipeline returns a nullable value and String inherits @/nullable or something like that
  • 1
    Also why the fuck are people afraid of nulls?
  • 0
    @yellow-dog They aren't afraid of nulls, but of libraries returning them when they are not expected.
    For example one class of the Apache Commons collections has method, annotated with @notnull but returns null if a condition is not met.
  • 1
    @yellow-dog

    Boils down to Tony Hoare considers implementing nulls a mistake.

    Lots of writing done on this one, ad nauseum:
    https://en.m.wikipedia.org/wiki/...
    https://medium.com/@elizarov/...
  • 0
    @yellow-dog and you experienced null pointer exceptions in C?
  • 2
    @QuanticoCEO As C doesn't have exceptions, this isn't possible. 🤷‍♂️

    On the other hand dereferencing a null pointer in C is undefined behaviour, but at most of the times it will lead to a segmentation fault instead.
  • 2
    You're probably interfacing with some Java code that returns a null. Kotlin treats all values coming from plain Java as "platform types" and allows silently assigning them to non-nullable Kotlin variables to reduce boilerplate.

    https://kotlinlang.org/docs/...
  • 0
    Got stuck in a work today, will be adding details or question when i reach home, till then this was the question i asked yesterday which would give some context:

    ( it was kinda theoretical question before doing the practical stuff, the practical stuff gave the results that made me write the rant, now i will be remaking a sample project to reverify my results when i reach home)

    https://stackoverflow.com/questions...
  • 1
    val isn’t actually a constant and doesn’t guarantee the value of the variable is going to be non-null. Mostly because you can add a getter to it and/or it’s value can depend on another variable which can be null.
  • 1
    no time to read comments or add details, will talk later : https://github.com/root-ansh/...
Add Comment