GoogleCloudPlatform / GoogleCloudPlatform/spring-cloud-gcp
GoogleStorageResource#getURL throws IllegalArgumentException if resource does not exist
- Dominant language
- Java
- Stars
- 551
- Forks
- 349
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 14
Description
**Describe the bug**
`com.google.cloud.spring.storage.GoogleStorageResource#getURL` currently uses `org.springframework.util.Assert#notNull` to check if the bucket or the blob could be resolved from GCS. `org.springframework.util.Assert#notNull` throws an `IllegalArgumentException` if the assertion fails. This violates the contract of `org.springframework.core.io.Resource#getURL` which specifies that a `java.io.IOException` should be thrown if the resource cannot be resolved as URL. The current behavior results in an HTTP 500 Internal Server Error e.g. during a static resource lookup with a GCS resource location configured if the resource path does not exist in GCS. The appropriate behavior of trying other configured resource locations and finally returning HTTP 404 Not Found can only be achieved by throwing a `java.io.IOException` (see `org.springframework.web.servlet.resource.PathResourceResolver#getResource(java.lang.String, jakarta.servlet.http.HttpServletRequest, java.util.List)`).
Contributor guide
Assessment
This issue has not been assessed yet.