Skip to content

[WIP] Fix BinaryExporter deserialization for multiple UserData lists#2610

Closed
Copilot wants to merge 6 commits intomasterfrom
copilot/fix-binaryexporter-deserialization-issue
Closed

[WIP] Fix BinaryExporter deserialization for multiple UserData lists#2610
Copilot wants to merge 6 commits intomasterfrom
copilot/fix-binaryexporter-deserialization-issue

Conversation

Copy link

Copilot AI commented Feb 11, 2026

  • Enable testLists=true in JmeExporterTest to reproduce the issue
  • Investigate the BinaryInputCapsule index issue
  • Identify root cause: Multiple UserData objects share BinaryClassObject and reuse field names/aliases
  • Implement fix: Use serialized unique ID field to generate unique prefixes
  • Address code review feedback: Use AtomicLong counter for guaranteed uniqueness
  • Run tests to verify the fix works
  • Request final code review
Original prompt

This section details on the original issue you should resolve

<issue_title>BinaryExporter fails when serializing multiple UserData objects containing lists</issue_title>
<issue_description>I was playing around with @copilot and it says it found this issue: #2607 (comment)

Reporting here for tracking, but i haven't validated it yet.


When a Spatial has multiple UserData entries containing lists (e.g., "int-list", "string-list", "float-list"), the BinaryExporter/BinaryImporter fails to deserialize correctly. The first list in the userData HashMap deserializes successfully, but subsequent lists return null and cause an ArrayIndexOutOfBoundsException during deserialization.

Steps to reproduce:

  1. Set testLists=true in jme3-plugins/src/test/java/com/jme3/export/JmeExporterTest.java (line 142)
  2. Run ./gradlew :jme3-plugins:test --tests "com.jme3.export.JmeExporterTest"
  3. Observe that BinaryImporter (Node 1) returns null for int-list and string-list, while float-list works (being first in iteration order)

Error:

java.lang.ArrayIndexOutOfBoundsException: Index -3 out of bounds for length 4
    at com.jme3.export.binary.ByteUtils.rightAlignBytes(ByteUtils.java:554)
    at com.jme3.export.binary.BinaryInputCapsule.readInt(BinaryInputCapsule.java:834)
    at com.jme3.export.binary.BinaryInputCapsule.setContent(BinaryInputCapsule.java:154)

Notes:

  • XMLExporter/XMLImporter works correctly with all lists
  • Only affects BinaryExporter when multiple UserData objects with lists exist
  • Appears to be a byte stream alignment issue in the binary format

</issue_description>

<agent_instructions>Validate the issue and if needed, propose a solution</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits February 11, 2026 22:36
Co-authored-by: riccardobl <4943530+riccardobl@users.noreply.github.com>
Use unique field name prefixes based on identity hash code to prevent field name collisions when multiple UserData objects with lists are serialized in the same binary file. This fixes the ArrayIndexOutOfBoundsException that occurred during deserialization.

Co-authored-by: riccardobl <4943530+riccardobl@users.noreply.github.com>
Replace System.identityHashCode() with a serialized uniqueId field that persists across write/read cycles. This ensures the same field name prefixes are used during both serialization and deserialization. Also adds backwards compatibility for old files.

Co-authored-by: riccardobl <4943530+riccardobl@users.noreply.github.com>
Replace System.nanoTime() with AtomicLong counter to ensure true uniqueness even with concurrent or rapid serialization. The counter starts at 0 and increments, so generated IDs (1, 2, 3...) never collide with the backwards-compatible fallback ("0").

Co-authored-by: riccardobl <4943530+riccardobl@users.noreply.github.com>
Co-authored-by: riccardobl <4943530+riccardobl@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.

BinaryExporter fails when serializing multiple UserData objects containing lists

2 participants