From b8aa9f0cdf94ec06f9d3a84d694795bed955e612 Mon Sep 17 00:00:00 2001 From: Ludy Date: Sun, 4 May 2025 18:20:07 +0200 Subject: [PATCH] Fix NullPointerException by Enabling Constructor Injection for Color Replacement Components (#3469) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 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. --- .../controller/api/misc/ReplaceAndInvertColorController.java | 2 +- .../SPDF/service/misc/ReplaceAndInvertColorService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/controller/api/misc/ReplaceAndInvertColorController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/ReplaceAndInvertColorController.java index 927b3a51f..865724a74 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/misc/ReplaceAndInvertColorController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/ReplaceAndInvertColorController.java @@ -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( diff --git a/src/main/java/stirling/software/SPDF/service/misc/ReplaceAndInvertColorService.java b/src/main/java/stirling/software/SPDF/service/misc/ReplaceAndInvertColorService.java index 20c20eb7b..e2a4e7ea5 100644 --- a/src/main/java/stirling/software/SPDF/service/misc/ReplaceAndInvertColorService.java +++ b/src/main/java/stirling/software/SPDF/service/misc/ReplaceAndInvertColorService.java @@ -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,