Skip to content

fix(java): honest Optional lookups; no crash on miss - #252

Merged
rahlk merged 3 commits into
mainfrom
fix/issue-248
Jul 14, 2026
Merged

fix(java): honest Optional lookups; no crash on miss#252
rahlk merged 3 commits into
mainfrom
fix/issue-248

Conversation

@rahlk

Copy link
Copy Markdown
Collaborator

Closes#248.

What

Java's entity lookups fell off the end of the function on a miss — implicit None under non-Optional annotations — and the first dereference crashed: get_method_parameters raised AttributeError for any typo'd class or signature; several internal call-graph and comments lookups shared the pattern. Fixed on both backends, three commits:

  • 8529a90: honest X | None annotations with explicit return None on get_method/get_class/get_java_file (ABC + both backends); get_method_parameters returns [] on miss (consistent with Python/TS); the two genuinely-unguarded internal call-graph consumers guarded (four others were already guarded on main); get_comments_in_a_method guarded.
  • 46abdcb: remaining crash sites — local get_comments_in_a_class, Neo4j get_comments_in_a_method/get_comments_in_a_class, Neo4j's mirrored __raw_call_graph_using_symbol_table_target_method internals.
  • b6d5bd5: the public facade (java_analysis.py) annotations made honest too (JType | None, JCallable | None, str | None); ABC docstring notes for the comments getters.

NO behavior change on hits anywhere. get_all_callers/get_all_callees miss shapes (bare {}) deliberately untouched — #249 owns them.

Tests

17 new miss-path tests: local via the established _write_java_output facade fixtures; Neo4j via JApplication-seeded backends (production reconstruction path, no driver needed); call-graph guards exercised through the public get_all_callers(using_symbol_table=True) entry. TDD RED (the AttributeErrors) → GREEN.

Gate on head b6d5bd5: tests/analysis/java127 passed, 4 skipped, 11 failed; all 11 failures are the pre-existing JDK-download/native-binary environment gaps, verified identical on unmodified main.

Notes for reviewers

  • Accepted lookup key forms (unchanged): exact qualified class name + exact method signature. Languages differ in accepted key forms — relevant for the future cross-language contract suite.
  • Annotation-only change surface on the facade: callers who type-check will now see Optional and be forced to handle the miss — that is the point.

rahlk added 3 commits July 14, 2026 11:06
get_method/get_class/get_java_file fell off the end on a miss under
non-Optional annotations (-> JCallable, -> JType), and
get_method_parameters dereferenced that implicit None unconditionally,
raising AttributeError on any typo'd class or signature.
- Annotate get_method/get_class/get_java_file Optional on both the
JCodeanalyzer and JNeo4jBackend implementations, with an explicit
return None on miss.
- get_method_parameters and get_comments_in_a_method now return []
on a miss instead of crashing.
- Guard the two unguarded internal get_method consumers in the
symbol-table call-graph construction path (target method and the
per-class enumeration loop) so a miss mid-construction skips the
entry instead of raising; behavior for found entries is unchanged.
Miss-shape semantics of get_all_callers/get_all_callees (the bare {})
are out of scope here; that's the 2.0.0 batch issue (#249).
Extends 8529a90 with the three remaining instances of the same
unguarded-dereference-on-miss pattern:
- JCodeanalyzer.get_comments_in_a_class: return [] instead of crashing
when the class lookup misses.
- JNeo4jBackend.get_comments_in_a_method / get_comments_in_a_class: same
fix, mirrored on the Neo4j backend.
- JNeo4jBackend.__raw_call_graph_using_symbol_table_target_method: guard
the internal get_method lookups so a miss skips the entry (or returns
the accumulated graph for the target-method case) instead of crashing,
mirroring the guards already applied to JCodeanalyzer's sibling method.
No behavior change on hits.
@rahlk
rahlk merged commit e7e289d into mainJul 14, 2026
@rahlk
rahlk deleted the fix/issue-248 branch July 14, 2026 15:59
@rahlkrahlk added the fix Bug fixes label Jul 14, 2026
@rahlkrahlk mentioned this pull request Jul 14, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixBug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant

@rahlk