Skip to content

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

Merged
dsilvam merged 3 commits into
mainfrom
fix/issue-35188-empty-binary-field-cast
Apr 22, 2026
Merged

fix(content-type): prevent ClassCastException on empty binary field in related contentlet (#35188)#35283
dsilvam merged 3 commits into
mainfrom
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 21s —— View job


dotCMS Backend Review

Tasks

  • Gather context and load conventions
  • Get Java diff
  • Run 4 parallel sub-agent reviews (Security, Database, Java Standards, REST API)
  • Consolidate findings
  • Post final review comment

All four sub-agents (Security, Database, Java Standards, REST API) returned no findings. The backend review comment has been updated with a clean result.

@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
dsilvam and others added 2 commits April 22, 2026 09:50
…ll host in GraphQL response

When BinaryViewStrategy skips writing empty binary field keys, BinaryFieldDataFetcher
was returning null (missing map key), causing GraphQL to resolve the binary field object
as null rather than an empty object with null properties.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dsilvam dsilvam added this pull request to the merge queue Apr 22, 2026
Merged via the queue into main with commit 5ff053d Apr 22, 2026
63 of 83 checks passed
@dsilvam dsilvam deleted the fix/issue-35188-empty-binary-field-cast branch April 22, 2026 23:08
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