Skip to content

bugfix/ErrorMessages reflective field scan runs before object is fully initialized#2856

Open
jutur wants to merge 1 commit into
OpenBankProject:developfrom
jutur:fix-errormessages-reflection-npe
Open

bugfix/ErrorMessages reflective field scan runs before object is fully initialized#2856
jutur wants to merge 1 commit into
OpenBankProject:developfrom
jutur:fix-errormessages-reflection-npe

Conversation

@jutur

@jutur jutur commented Jul 11, 2026

Copy link
Copy Markdown

Related to #2624
allFields (used to build the Swagger error-code lookup table) reflectively scans this object's own declared fields, but as an eager val this scan can run while the ErrorMessages object is still being constructed. Fields declared later in the file (errorToCode, isValidName) are not yet assigned at that point, and the outcome depends on JVM/reflection field-ordering, which the JVM spec doesn't guarantee and which can differ between environments (e.g. a local run vs. a packaged Docker deployment).

Making allFields a lazy val defers the reflective scan until first actual use. Its only consumer (SwaggerJSONFactory.errorDefinitions) accesses it well after application boot during on-demand Swagger doc generation, so by then the object is guaranteed to be fully initialized regardless of field-declaration order.

I have read and agree to the Harmony Individual Contributor Assignment Agreement (Harmony_Individual_Contributor_Assignment_Agreement.txt).

Signed: Abhinav Reddy

…y initialized

allFields (used to build the Swagger error-code lookup table) reflectively
scans this object's own declared fields, but as an eager val this scan can
run while the ErrorMessages object is still being constructed. Fields
declared later in the file (errorToCode, isValidName) are not yet assigned
at that point, and the outcome depends on JVM/reflection field-ordering,
which the JVM spec doesn't guarantee and which can differ between
environments (e.g. a local run vs. a packaged Docker deployment).

Making allFields a lazy val defers the reflective scan until first actual
use. Its only consumer (SwaggerJSONFactory.errorDefinitions) accesses it
well after application boot during on-demand Swagger doc generation, so
by then the object is guaranteed to be fully initialized regardless of
field-declaration order.

I have read and agree to the Harmony Individual Contributor Assignment
Agreement (Harmony_Individual_Contributor_Assignment_Agreement.txt).

Signed: Abhinav Reddy
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant