core icon indicating copy to clipboard operation
core copied to clipboard

[DEFECT] Improve error handling for asset upload when 'System Indexed' is unchecked

Open dario-daza opened this issue 9 months ago • 3 comments

Problem Statement

When a client using the Asset API (PUT /api/v1/assets) tries to upload assets with the "System Indexed" option unchecked on the "File Asset" field of the "File Asset" content type, the API returns a 500 error. This error is not informative and makes it difficult to troubleshoot the issue. The API should handle this scenario gracefully and provide a clear error message.

Steps to Reproduce

  1. In dotCMS, navigate to the Content Model -> Content Types.
  2. Edit the "File Asset" content type.
  3. Edit the "File Asset" field.
  4. Uncheck the "System Indexed" option and save.
  5. Reindex the File Asset Content Type (Maintenance/INDEX tab).
  6. Attempt to upload a file asset using the PUT /api/v1/assets endpoint.
  7. Observe the 500 Internal Server Error response.

Acceptance Criteria

  • [ ] When uploading an asset via the API and the "System Indexed" option is unchecked, the API should not return a 500 error.
  • [ ] The API should return a meaningful error response (e.g., a 4xx status code) with a message indicating that the "System Indexed" option must be enabled for the "File Asset" field.

dotCMS Version

Latest from main branch

Severity

Medium - Some functionality impacted

Links

Ticket support

dario-daza avatar Feb 06 '26 16:02 dario-daza

Experienced the same problem on 24.12.27_lts_v15 version (but see the same code on main branch). Issue seems to be in WebAssetHelper.java -> AssetView toAsset(final FileAsset fileAsset) method and this part of the method.

Map.of() does not accept nulls in key/value.

 final Map<String, ? extends Serializable> metadata = Map.of(
                "name", fileAsset.getUnderlyingFileName(),
                "title", fileAsset.getFileTitle(),
                "path", fileAsset.getPath(),
                "sha256", fileAsset.getSha256(),
                "contentType", fileAsset.getMimeType(),
                "size", fileAsset.getFileSize(),
                "isImage", fileAsset.isImage(),
                "width", fileAsset.getWidth(),
                "height", fileAsset.getHeight(),
                SORT_BY, fileAsset.getModDate().toInstant()
        );

Exception:

java.lang.NullPointerException: null
        at java.base/java.util.Objects.requireNonNull(Objects.java:233) ~[?:?]
        at java.base/java.util.ImmutableCollections$MapN.<init>(ImmutableCollections.java:1193) ~[?:?]
        at java.base/java.util.Map.of(Map.java:1626) ~[?:?]
        at com.dotcms.rest.api.v1.asset.WebAssetHelper.toAsset(WebAssetHelper.java:310) ~[?:?]
        at com.dotcms.rest.api.v1.asset.WebAssetHelper.saveUpdateAsset(WebAssetHelper.java:503) ~[?:?]
        at com.dotcms.rest.api.v1.asset.WebAssetResource.saveUpdateAsset(WebAssetResource.java:140) ~[?:?]
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[?:?]
        at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[?:?]
�       at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52) ~[?:?]
�       at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:124) ~[?:?]
�       at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:167) ~[?:?]
�       at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:176) ~[?:?]
�       at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaRe

adrianpanek avatar Feb 07 '26 21:02 adrianpanek

PRs linked to this issue

github-actions[bot] avatar Feb 13 '26 19:02 github-actions[bot]

Passed QA

  • dotCMS docker image: [dotcms/dotcms:trunk]

Video

https://github.com/user-attachments/assets/0c0c7112-fccf-4741-8c5b-950912264723

ihoffmann-dot avatar Feb 20 '26 19:02 ihoffmann-dot