https://kotlinlang.org logo
#codereview
Title
# codereview
s

SomeCat

02/05/2021, 3:09 PM
Untitled
m

Matteo Mirk

02/05/2021, 4:04 PM
the return statement will throw NPE if key is null, maybe you want to handle it differently?
s

SomeCat

02/05/2021, 6:21 PM
I think the log error call throws already and exits.
But you are probably correct, I should throw an exception instead.
m

Matteo Mirk

02/08/2021, 10:21 AM
No, the log error doesn’t throw because you’re not dereferencing
key
, even better without safe call operators it won’t even compile. Anyway, after the initial check on the file you shouldn’t continue the execution: it’s useless to the logic you want. Instead you should either return early with some meaningful value (
null
or
Result
), or you should throw in each case. Don’t log and throw, do either but not both.
s

SomeCat

02/09/2021, 7:12 AM
Yeah, I got two good responses on SO that went the same path. The more interesting aspect is that I now get to the impression that just having such code in gradle is already a smell. That API key should rather come out of a provider, or maybe some properties file.
m

Matteo Mirk

02/09/2021, 9:10 AM
Oh is it a Gradle task? Yes, maybe try to see if there’s a built-in mechanism to do that.
s

SomeCat

02/12/2021, 12:23 PM
Yeah, we figured that we definitely need our users to have a local gradle.properties for some things we cant do in code. With that requirement, we just told them to have all relevant information in that file. So we can just pull from there, without all the extra effort
👍 1
5 Views