Fix the nullability audit for a Kotlin migration

Review the AI's codeEasy12 minGoogle style

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".
  • annotation is the Java side's annotation: nonnull, nullable or none (no annotation at all).
  • declared is the Kotlin return type the agent wrote. A trailing ? makes it nullable.
  • observed_null is true when the method was seen returning null at runtime, else false.
  • 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 annotation and observed_null without regard to case.
  • A declared type is nullable only when it ends with ?.
  • A non-null declaration is proven only when annotation is nonnull and observed_null is false. 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
Inputaudit_kotlin_nullability(["loadProfile|none|UserProfile|true", "findAll|nonnull|List<User>|false", "lookup|nullable|Token?|true"])
Output["loadProfile"]
Example 2
Inputaudit_kotlin_nullability(["saveDraft|nonnull|Draft|true"])
Output["saveDraft"]
Example 3
Inputaudit_kotlin_nullability([])
Output[]