Skip to content

fix: [OData v4] Make VDM entity fields accessible once in GsonVdmEntityAdapter - #1323

Open
MaxonT wants to merge 1 commit into
SAP:mainfrom
MaxonT:contrib/1226-auto
Open

MaxonT wants to merge 1 commit into
SAP:mainfrom
MaxonT:contrib/1226-auto

Conversation

@MaxonT

@MaxonT MaxonT commented Nov 25, 2026

Copy link
Copy Markdown

Taking up #1226 as I said there: the adapter now makes the shared fields accessible once, so concurrent reads and writes no longer reset each other's access.

GsonVdmEntityAdapter keeps java.lang.reflect.Field objects in a map that is shared by every thread using the same Gson instance. On each read and write it called setAccessible(true), used the field, and then restored the previous value with setAccessible(false). Because the Field object is shared, one thread's restore can run between another thread's setAccessible(true) and Field.get(), which fails intermittently with IllegalAccessException (logged as "Could not serialize property ... Returning null instead").

This change calls setAccessible(true) once, when the adapter builds its property map, and removes the per-call toggling in read and getEntityAsJsonObject. The fields are the private fields of generated VDM classes, which were already made accessible on every call, so no new access is opened.

Added GsonVdmEntityAdapterConcurrencyTest, which serializes and deserializes a Person and asserts that the shared fields are still accessible afterwards. It checks the cause deterministically instead of relying on thread timing. Added a line to release_notes.md.

Tests run: mvn -pl datamodel/odata-v4/odata-v4-core -am test -Dtest='GsonVdm*Test' passes; the whole com.sap.cloud.sdk.datamodel.odatav4 test set in that module passes (276 run, 0 failures, 12 skipped). With the fix reverted, the new test fails. I removed three explanatory code comments after that run to follow the project's no-comments guideline; the code is otherwise unchanged and was not re-run.

Not verified: I did not run the 100-thread reproduction from the issue, and did not run other modules or the full build.

Definition of Done:

  • Functionality scope stated & covered
  • Tests cover the scope above
  • Error handling created / updated & covered by the tests above
  • Documentation updated
  • Release notes updated

Refs #1226

…tyAdapter

Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
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

⌂ Proxy