Fix the nullability audit for a Kotlin migration
Your task
An AI agent converted your Android service layer from Java to Kotlin, and the beta channel now shows NullPointerExceptions the Java code never had. A Java value with no nullability annotation reaches Kotlin as a platform type, which Kotlin lets you treat as non-null. You want an audit of every non-null return type the agent declared without proof.
An assistant wrote audit_kotlin_nullability(entries). It is in the editor. It has a bug. Find it and fix it.
Input and output:
entries: one string per converted method,"name|annotation|declared|observed_null".annotationis the Java side's annotation:nonnull,nullableornone(no annotation at all).declaredis the Kotlin return type the agent wrote. A trailing?makes it nullable.observed_nullistruewhen the method was seen returning null at runtime, elsefalse.- Return the names of the flagged methods.
Rules the tests check:
- Split each entry on
|. Skip an entry with fewer than 4 parts. Ignore any parts after the fourth. - Trim whitespace from all four fields. Compare
annotationandobserved_nullwithout regard to case. - A declared type is nullable only when it ends with
?. - A non-null declaration is proven only when
annotationisnonnullandobserved_nullisfalse. Any other value, including an unknown one, proves nothing. - Flag an entry when its declared type is not nullable and not proven.
- Return the trimmed names in input order. Keep duplicates.
Examples
audit_kotlin_nullability(entries: list[str]) -> list[str]Example 1
Input
audit_kotlin_nullability(["loadProfile|none|UserProfile|true", "findAll|nonnull|List<User>|false", "lookup|nullable|Token?|true"])Output
["loadProfile"]Example 2
Input
audit_kotlin_nullability(["saveDraft|nonnull|Draft|true"])Output
["saveDraft"]Example 3
Input
audit_kotlin_nullability([])Output
[]