Skip to content

Conversation

@lukaszlenart
Copy link
Member

Summary

  • Fix WW-5602: When contentCharSet is an expression that evaluates to null, the content-type header was incorrectly appending ;charset= with no value
  • Refactor: Extract methods and modernize StreamResult to improve extensibility and code quality

Changes

Bug Fix (WW-5602)

  • Evaluate contentCharSet expression before checking for emptiness
  • Call setCharacterEncoding(null) to clear Dispatcher's default UTF-8 encoding when no charset is specified
  • Add test case for expression evaluating to null

Refactoring

  • Add constants: DEFAULT_BUFFER_SIZE, DEFAULT_CONTENT_TYPE, DEFAULT_CONTENT_DISPOSITION, DEFAULT_INPUT_NAME
  • Extract protected methods for easy extension:
    • resolveInputStream() - custom stream sources (database, cloud, generated)
    • applyResponseHeaders() - custom headers (ETag, X-Custom)
    • applyContentLength() - custom length calculation
    • streamContent() - custom buffering, compression, encryption
  • Use try-with-resources for cleaner resource management
  • Add JavaDoc explaining extensibility of each method

Test plan

  • All 18 StreamResultTest tests pass
  • New test testStreamResultWithNullCharSetExpression verifies the bug fix

Closes WW-5602

🤖 Generated with Claude Code

lukaszlenart and others added 3 commits January 4, 2026 14:08
- Evaluate contentCharSet expression before checking for emptiness
- Use StringUtils.isEmpty() for null/empty check on parsed value
- Call setCharacterEncoding(null) to clear Dispatcher's default encoding
- Set charset via setCharacterEncoding() instead of appending to content-type
- Add test for expression evaluating to null

Closes WW-5602

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Add constants: DEFAULT_BUFFER_SIZE, DEFAULT_CONTENT_TYPE,
  DEFAULT_CONTENT_DISPOSITION, DEFAULT_INPUT_NAME
- Extract resolveInputStream() for custom stream sources
- Extract applyResponseHeaders() for custom header handling
- Extract applyContentLength() for custom length calculation
- Extract streamContent() for custom streaming behavior
- Use try-with-resources for cleaner resource management
- Add JavaDoc explaining extensibility of each method

All extracted methods are protected to enable easy extension
by users creating custom streaming result types.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Cast null to String to disambiguate between overloaded methods:
- setCharacterEncoding(String)
- setCharacterEncoding(Charset)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 4, 2026

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