langchain4j/document-loaders/langchain4j-document-loader.../src
Eunbin Son af99cec384
fix: Guard against null content type in GcsSource metadata (#5673)
## Issue
Closes #5672

## Change
`GcsSource` built its metadata by calling `metadata.put("contentType",
blob.getContentType())`. `Blob.getContentType()` is nullable, and core
`Metadata.put(String, String)` rejects null with an
`IllegalArgumentException`. Loading a valid, non-empty object without a
content type therefore failed: `loadDocument()` threw, and
`loadDocuments()` caught the exception and silently skipped the object.

This change skips the `contentType` key when `getContentType()` returns
null, so the key is absent rather than holding a meaningless `"null"`
string. The sibling `AzureBlobStorageSource` already guards its metadata
(via `String.valueOf`); this brings the GCS loader in line. Scope is
limited to the `contentType` line.

Added `GcsSourceTest` with a Mockito-mocked `Blob`: a regression case
(null content type builds successfully, key absent) and a positive case
(`text/plain` preserved).

## General checklist
- [X] There are no breaking changes (API, behaviour)
- [X] I have added unit and/or integration tests for my change
- [X] The tests cover both positive and negative cases
- [X] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [ ] I have manually run all the unit and integration tests in the core
and main modules, and they are all green
- [ ] I have added/updated the documentation
- [ ] I have added an example in the examples repo (only for "big"
features)
- [ ] I have added/updated Spring Boot starter(s) (if applicable)
2026-07-01 11:14:12 +02:00
..
main/java/dev/langchain4j/data/document fix: Guard against null content type in GcsSource metadata (#5673) 2026-07-01 11:14:12 +02:00
test/java/dev/langchain4j/data/document fix: Guard against null content type in GcsSource metadata (#5673) 2026-07-01 11:14:12 +02:00