Roar Gronmo
01/30/2020, 8:18 PM@Query("SELECT * FROM stations WHERE stationId = :stationId LIMIT 1")
fun getStation(stationId: String): Station
What will happen if ":stationID" is not found, how is that element returned, null ?
Above expression is set as "nullsafe" (No warning telling that I should return Station?
instead,) and handle the null check in my code.
AS should give a Lint Error/Warning here to tell that the result may return null.
My app fails at this point when handling a null (that obviously shouldn't be null...)
RGRoar Gronmo
01/30/2020, 8:23 PMkyleg
01/31/2020, 12:17 AMRoar Gronmo
01/31/2020, 6:12 AMkyleg
02/14/2020, 2:59 PM_impl
is autogenerated Java, and Java has no nullable marker, so your linter cannot possibly know that the Java function could return null.kyleg
02/14/2020, 3:04 PMinterface
code SELECTs from the table, you should always put a ?
at the end of your return value if you’re querying a single value.
Don’t do:
@Query("SELECT * FROM foo LIMIT 1")
fun getFoo(): Foo
Do:
@Query("SELECT * FROM foo LIMIT 1")
fun getFoo(): Foo?
or
@Query("SELECT * FROM foo LIMIT 1")
fun getFoo(): LiveData<Foo>
(the latter bakes in a warning about nullability since LiveData<A>.value: A?
by definitionRoar Gronmo
02/14/2020, 3:06 PMkyleg
02/14/2020, 3:08 PM@NotNull/@Nullable
annotation), your linter would probably highlight almost every Java function you call since most of them do not have those annotations (since they’re optional).kyleg
02/14/2020, 3:08 PMkyleg
02/14/2020, 3:10 PM@Query("SELECT * FROM Foo")
fun getFoo(): Foo?
The query might select 50 rows, and it will pick 1 to return back. A query missing a LIMIT should error out on compile if your return value is not List<A>
Roar Gronmo
02/14/2020, 3:10 PMkyleg
02/14/2020, 3:11 PMRoar Gronmo
02/14/2020, 3:13 PM