fix(java): correct Lombok @RequiredArgsConstructor/@AllArgsConstructor DI semantics#589
Open
YutenC wants to merge 1 commit into
Open
fix(java): correct Lombok @RequiredArgsConstructor/@AllArgsConstructor DI semantics#589YutenC wants to merge 1 commit into
YutenC wants to merge 1 commit into
Conversation
…DI semantics @requiredargsconstructor previously only detected final fields, missing @NonNull-annotated non-final fields which Lombok also includes in the generated constructor. @AllArgsConstructor was treated identically to @requiredargsconstructor (only final fields), but its correct semantics is all non-static fields regardless of final or @nonnull. Changes: - Split has_lombok_constructor into has_required_args / has_all_args so each annotation applies its own field-selection rule - @requiredargsconstructor: final || @nonnull (non-static) - @AllArgsConstructor: every non-static field - New injection_type value 'constructor_lombok_all' for @AllArgsConstructor edges; existing 'constructor_lombok' preserved for @requiredargsconstructor Tests: - Add PaymentService fixture (RequiredArgsConstructor + @nonnull non-final field) - Add ReportService fixture (AllArgsConstructor with non-final fields) - test_required_args_nonnull_field_injected - test_required_args_plain_field_not_injected - test_all_args_injects_all_non_static_fields - Update test_total_injects_edge_count (4 → 8 minimum edges)
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 free
to 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.
Problem
v2.3.3 introduced Spring DI resolution via
_emit_spring_field_injection(), but the Lombok constructor annotation handling has two semantic bugs:1.
@RequiredArgsConstructormisses@NonNullfieldsLombok's
@RequiredArgsConstructorgenerates a constructor forfinalfields and@NonNull-annotated non-final fields. The current implementation only checkshas_final, so@NonNullfields silently produce noINJECTSedge.2.
@AllArgsConstructorbehaves like@RequiredArgsConstructor@AllArgsConstructorgenerates a constructor for all non-static fields regardless offinalor@NonNull. The current code shares the samehas_lombok_constructor and has_finalguard, so non-final fields in an@AllArgsConstructorclass are never resolved.Fix
Split
has_lombok_constructor: boolinto two flags and apply the correct Lombok field-selection rule for each annotation:@RequiredArgsConstructorfinalor@NonNull(non-static)@AllArgsConstructorA new
injection_typevalue"constructor_lombok_all"is introduced for@AllArgsConstructoredges. The existing"constructor_lombok"value is preserved for@RequiredArgsConstructor— no breaking change to existing graphs.Changes
code_review_graph/parser.py—_emit_spring_injections()and_emit_spring_field_injection()tests/fixtures/SpringDI.java— addPaymentService(@RequiredArgsConstructor+@NonNullnon-final field) andReportService(@AllArgsConstructorwith non-final fields)tests/test_multilang.py— three new tests, updated edge count assertionTests