Fix NullPointerException by Enabling Constructor Injection for Color Replacement Components (#3469)

# Description of Changes

Please provide a summary of the changes, including:

- **What was changed**  
Added the `final` modifier to the `ReplaceAndInvertColorService` field
in `ReplaceAndInvertColorController` and to the
`ReplaceAndInvertColorFactory` field in `ReplaceAndInvertColorService`.
This ensures that Lombok’s `@RequiredArgsConstructor` generates
constructors for these dependencies, enabling proper constructor-based
injection instead of leaving them null.

- **Why the change was made**  
Without the `final` keyword, Lombok does not include non-final fields in
the generated constructor, causing Spring to leave them uninitialized
and resulting in a `NullPointerException` during runtime when invoking
`replaceAndInvert` on the factory/service.

---

## Checklist

### General

- [x] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [x] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md)
(if applicable)
- [x] I have performed a self-review of my own code
- [x] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing)
for more details.
This commit is contained in:
Ludy 2025-05-04 18:20:07 +02:00 committed by GitHub
parent 5ca956f033
commit b8aa9f0cdf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View File

@ -25,7 +25,7 @@ import stirling.software.SPDF.service.misc.ReplaceAndInvertColorService;
@RequiredArgsConstructor
public class ReplaceAndInvertColorController {
private ReplaceAndInvertColorService replaceAndInvertColorService;
private final ReplaceAndInvertColorService replaceAndInvertColorService;
@PostMapping(consumes = "multipart/form-data", value = "/replace-invert-pdf")
@Operation(

View File

@ -16,7 +16,7 @@ import stirling.software.SPDF.utils.misc.ReplaceAndInvertColorStrategy;
@Service
@RequiredArgsConstructor
public class ReplaceAndInvertColorService {
private ReplaceAndInvertColorFactory replaceAndInvertColorFactory;
private final ReplaceAndInvertColorFactory replaceAndInvertColorFactory;
public InputStreamResource replaceAndInvertColor(
MultipartFile file,