Having String.toByteArray(null) is confusing


#1

Hi there,

I think allowing String.toByteArray(null) to perform default string to byes is confusing. Why not create two overloaded methods, one without parameter, and then second with non-null able encode param?

On top of this there is also String.toByteArray(encode : Charset) declared. Obviously this is not-nullable, and that’s the only reason it compiles I suppose. But to me, allowing String.toByteArray(null) is ugly and confusing.

-Zemian


#2

Good point. Feel free to report it to the tracker (and along with a fix, if you like :) )


#3

http://youtrack.jetbrains.com/issue/KT-3533

Also included a pull request for you there.

It turned out few other areas are using the same null passing as way to indicate default encoding. I fixed all those occurance as well.

Note that this will break user API if they already started using nullable encoding name such as toByteArray(null), because the signature now has changed to more stricter one. You may review and see if that good or not.

-Z