Skip to content

fix(content-type): prevent ClassCastException on empty binary field in related contentlet (#35188)#35283

Open
dsilvam wants to merge 1 commit intomainfrom
fix/issue-35188-empty-binary-field-cast
Open

fix(content-type): prevent ClassCastException on empty binary field in related contentlet (#35188)#35283
dsilvam wants to merge 1 commit intomainfrom
fix/issue-35188-empty-binary-field-cast

Conversation

@dsilvam
Copy link
Copy Markdown
Member

@dsilvam dsilvam commented Apr 10, 2026

Summary

  • Root cause: When a contentlet with an empty binary field is used as related content at depth≥1, BinaryViewStrategy unconditionally wrote emptyMap() into the contentlet's backing map under the bare field variable key (when AVOID_MAP_SUFFIX_FOR_VIEWS is set). A subsequent DefaultTransformStrategy.addBinaries call then invoked Contentlet.getBinary(), which tried to cast emptyMap() to File, throwing a ClassCastException wrapped as DotDataException: null.
  • Fix (root cause): BinaryViewStrategy now skips the map.put when transform(field, contentlet) returns an empty map — nothing is written for fields with no uploaded file.
  • Fix (defensive): Contentlet.getBinary() now uses an instanceof File guard before casting, so any future map poisoning cannot cause a ClassCastException.
  • Tests: Two new unit tests — BinaryViewStrategyTest (2 cases) and a new case in ContentletTest — covering both fixes. All 5 tests pass.

Test plan

  • Existing ContentletTransformerTest (27 tests) — all pass
  • New BinaryViewStrategyTest — 2 tests pass
  • New ContentletTest#testGetBinary_whenMapContainsNonFileValue_returnsNullWithoutException — passes
  • Manual: Page API GET /api/v1/page/json/{page}?depth=1 with a related contentlet that has an empty binary field — no ClassCastException / DotDataException: null in logs

Closes #35188

🤖 Generated with Claude Code

…n related contentlet (#35188)

Skip writing emptyMap() into the contentlet map when binary metadata is null (BinaryViewStrategy),
and add a defensive instanceof guard in Contentlet.getBinary() to prevent ClassCastException from
any future map poisoning. Adds unit tests covering both fixes.

Refs: #35188

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cursor
Copy link
Copy Markdown

cursor bot commented Apr 10, 2026

You have used all of your free Bugbot PR reviews.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Apr 10, 2026

Claude finished @dsilvam's task in 2m 1s —— View job


Claude finished @dsilvam's task in 2m 26s —— View job


dotCMS Backend Review

  • Load dotCMS conventions
  • Get Java diff
  • Run parallel security, database, Java standards, and REST API reviews
  • Consolidate findings and post review

All four review domains came back clean — no security, database, Java standards, or REST API issues found.

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Apr 10, 2026

Claude finished @dsilvam's task in 3m 41s —— View job


I'll analyze this and get back to you.

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Apr 10, 2026

dotCMS Backend Review: no issues found.

@dsilvam dsilvam enabled auto-merge April 10, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI: Safe To Rollback Area : Backend PR changes Java/Maven backend code

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

ClassCastException when rendering page with empty binary field in related contentlet

3 participants