Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ void restoreError(EventContext context) {
String maxSizeStr = (String) context.get("attachment.MaxSize");
if (maxSizeStr != null) {
throw new ServiceException(
ExtendedErrorStatuses.CONTENT_TOO_LARGE, "AttachmentSizeExceeded", maxSizeStr);
ExtendedErrorStatuses.CONTENT_TOO_LARGE,
"File size exceeds the limit of {}.",
maxSizeStr);
Comment on lines +85 to +87
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best Practice: Hard-coded error message strings are not localizable

The old approach used a message key ("AttachmentSizeExceeded") looked up from messages.properties, which allowed the CAP framework to resolve the message from locale-specific bundles (e.g. i18n_de.properties). Replacing this with hard-coded English strings in all three throw sites (CreateAttachmentsHandler, ModifyApplicationHandlerHelper, CountingInputStream) and deleting messages.properties removes i18n support for this error message. End users who have a non-English locale will now always see the English text.

Consider adding the message key(s) to the existing CDS i18n bundle (_i18n/i18n.properties) and using a message key reference instead of a literal string, consistent with how the framework resolves other user-facing messages:

# in _i18n/i18n.properties
AttachmentSizeExceeded=File size exceeds the limit of {0}.
AttachmentSizeExceededNoLimit=File size exceeds the limit.

Then use the key in the ServiceException constructor:

throw new ServiceException(
    ExtendedErrorStatuses.CONTENT_TOO_LARGE,
    "AttachmentSizeExceeded",
    maxSizeStr);

Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

}
throw new ServiceException(
ExtendedErrorStatuses.CONTENT_TOO_LARGE, "AttachmentSizeExceeded");
ExtendedErrorStatuses.CONTENT_TOO_LARGE, "File size exceeds the limit.");
}
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ public static InputStream handleAttachmentForEntity(
maxSizeStr); // make max size available in context for error handling later
ServiceException tooLargeException =
new ServiceException(
ExtendedErrorStatuses.CONTENT_TOO_LARGE, "AttachmentSizeExceeded", maxSizeStr);
ExtendedErrorStatuses.CONTENT_TOO_LARGE,
"File size exceeds the limit of {}.",
maxSizeStr);

if (contentLength != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ private void checkLimit(long bytes) {
byteCount += bytes;
if (byteCount > maxBytes) {
throw new ServiceException(
ExtendedErrorStatuses.CONTENT_TOO_LARGE, "AttachmentSizeExceeded", maxBytesString);
ExtendedErrorStatuses.CONTENT_TOO_LARGE,
"File size exceeds the limit of {}.",
maxBytesString);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void restoreError_contentTooLargeWithMaxSize_throwsWithMaxSize() {
var exception = assertThrows(ServiceException.class, () -> cut.restoreError(context));

assertThat(exception.getErrorStatus()).isEqualTo(ExtendedErrorStatuses.CONTENT_TOO_LARGE);
assertThat(exception.getMessage()).contains("AttachmentSizeExceeded");
assertThat(exception.getMessage()).contains("File size exceeds the limit of 10MB.");
assertThat(exception).isNotSameAs(originalException);
}

Expand All @@ -355,7 +355,7 @@ void restoreError_contentTooLargeWithoutMaxSize_throwsWithoutMaxSize() {
var exception = assertThrows(ServiceException.class, () -> cut.restoreError(context));

assertThat(exception.getErrorStatus()).isEqualTo(ExtendedErrorStatuses.CONTENT_TOO_LARGE);
assertThat(exception.getMessage()).contains("AttachmentSizeExceeded");
assertThat(exception.getMessage()).contains("File size exceeds the limit.");
assertThat(exception).isNotSameAs(originalException);
}

Expand Down
5 changes: 5 additions & 0 deletions doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).

The format is based on [Keep a Changelog](http://keepachangelog.com/).

## Version 1.3.3 - 2026-03-15

### Fixed
- Fixed @Validation.Maximum error message not showing in consuming projects due to messages.properties being overwritten instead of merged. Error messages are now temporary self-contained and no longer rely on a resource bundle.

## Version 1.3.2 - 2026-03-10

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</distributionManagement>

<properties>
<revision>1.4.0-SNAPSHOT</revision>
<revision>1.3.3-SNAPSHOT</revision>
<java.version>17</java.version>
<maven.compiler.release>${java.version}</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
2 changes: 1 addition & 1 deletion samples/bookshop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<dependency>
<groupId>com.sap.cds</groupId>
<artifactId>cds-feature-attachments</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
Loading