Status Update
Comments
da...@google.com <da...@google.com> #2
tn...@google.com <tn...@google.com> #3
I think the problem here is that you're using a default use site with the annotation; this means you have annotated the private field, not the getter or setter for that property!
Instead, you should use (in the @Insert annotation) a declaration like this:
@get:OnConflictStrategy
val onConflict: Int = OnConflictStrategy.ABORT
Once you do lint should enforce it.
(I looked at that other bug; it does not look like a bug to me; I'll add comments there.)
tn...@google.com <tn...@google.com> #4
P.S. Default use sites continue to be a problem confusing developers. We have a potential lint check to help flag this in ag/15872109.
da...@google.com <da...@google.com> #5
Ah default use sites! Not the first time it has bitten me! Thank you sooo much for the clarification. I didn't even consider it since @Insert
being an annotation does not have fields, only getters, so I thought maybe Kotlin would place it in the right spot since it doesn't have to do the gymnastics to figure out whether to put it in a synthetic method, in the backing field, setter or getter. Anyway, I'll close this now, thanks again!
Description
Room recently moved some of its APIs and source from Java to Kotlin and int def enforcement seems to have been lost with the move.
Given the IntDef in Room OnConflictStrategy , wrong usage of it in Kotlin gives no warning:
the enforcement is also lost in Java sources:
However, if I make a new
@IntDef
along with an annotation in Java, the enforcement works fine.Let me know if you need more information!