Uh oh!
There was an error while loading. Please reload this page.
fix(java): honest Optional lookups; no crash on miss - #252
Merged
Conversation
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.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes#248.
What
Java's entity lookups fell off the end of the function on a miss — implicit
Noneunder non-Optional annotations — and the first dereference crashed:get_method_parametersraisedAttributeErrorfor any typo'd class or signature; several internal call-graph and comments lookups shared the pattern. Fixed on both backends, three commits:8529a90: honestX | Noneannotations with explicitreturn Noneonget_method/get_class/get_java_file(ABC + both backends);get_method_parametersreturns[]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_methodguarded.46abdcb: remaining crash sites — localget_comments_in_a_class, Neo4jget_comments_in_a_method/get_comments_in_a_class, Neo4j's mirrored__raw_call_graph_using_symbol_table_target_methodinternals.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_calleesmiss shapes (bare{}) deliberately untouched — #249 owns them.Tests
17 new miss-path tests: local via the established
_write_java_outputfacade fixtures; Neo4j viaJApplication-seeded backends (production reconstruction path, no driver needed); call-graph guards exercised through the publicget_all_callers(using_symbol_table=True)entry. TDD RED (the AttributeErrors) → GREEN.Gate on head
b6d5bd5:tests/analysis/java— 127 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
Optionaland be forced to handle the miss — that is the point.