Returning nullable to java from kotlin always results in null


#1

So i have a method, for example:

fun getBitmap(...): Bitmap? {
    //.. come code
    return result // this is a Bitmap? - nullable bitmap.
}

When i call this method from Java using the file name, BitmapUtilsKt.getBitmap() it returns always null, even when in debug mode on the return line the result was not null.

So, seems that there is a problem converting nullable Bitmap to java’s not nullable Bitmap, that always results in null.

Is this a bug? How do i continue working with this code? Making the method return not nullable Bitmap seems impossible for me now. As i understand, java should receive the Bitmap from this method successfully.


#2

Debugger is not always reliable due to caching and other issues. Try to insert nullness check and throw an exception or log message in case result is null when you expect it not to be.


#3

Yes, i have made a log inside the function, and the problem was not about kotlin-java interaction. Something was wrong in my code. Thanks for the hint!