Skip to content

fix(java): implicit-None lookups under non-Optional annotations; get_method_parameters crashes on miss #248

Description

@rahlk

PROBLEM

The Java backends' entity lookups fall off the end of the function on a miss — implicit None under non-Optional annotations (-> JCallable, -> JType) — and the first dereference turns a benign miss into a crash: get_method_parameters raises AttributeError: 'NoneType' object has no attribute 'parameters' for any typo'd class or signature. Seven internal call sites dereference get_method results unchecked.

AFFECTED CODE (audit classes C1-C3)

  • cldk/analysis/java/codeanalyzer/codeanalyzer.py:475 — get_method implicit None, annotated -> JCallable; same file get_class, get_java_file share the pattern
  • cldk/analysis/java/codeanalyzer/codeanalyzer.py:503 — get_method_parameters crashes on miss
  • cldk/analysis/java/codeanalyzer/codeanalyzer.py:738, :741, :769, :775, :808, :846, :1083 — unguarded internal consumers (symbol-table call-graph paths, latent crashes)
  • cldk/analysis/java/neo4j/neo4j_backend.py:461, :472 — same get_method / get_method_parameters pair on the Neo4j backend; get_java_file implicit None too

FIX CONTRACT

  1. Honest annotations: get_method/get_class/get_java_file (both backends) return Optional[...] with explicit return None.
  2. get_method_parameters returns [] on miss (consistent with the Python/TS backends' documented behavior) instead of crashing.
  3. Guard the internal consumers: a miss mid-call-graph-construction must not raise AttributeError (skip the entry; existing behavior for found entries unchanged).
  4. NO behavior change on hits; no signature changes beyond Optional annotations. Miss-shape semantics of get_all_callers/get_all_callees (bare {}, audit class C4) are explicitly OUT of scope — that is the 2.0.0 batch issue.

DEFINITION OF DONE

  • Failing tests first: miss on get_method_parameters returns [] (no crash), get_method miss returns None under Optional annotation, on both backends.
  • Existing tests green; mypy/annotation check passes on the touched files.
  • Branch fix/issue-NNN; one PR closes this.

Found in the 2026-07-09 lookup audit (see #238 discussion; F1 oracle note on #239).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions