Stirling-PDF/app
Balázs Szücs 60c7ba40a6
fix(scale): Throw exceptions for invalid page size instead of returning null in getTargetSize method (#4460)
# Description of Changes

Fixed getTargetSize to never make an early null return, instead throw an
appropriate customException when the submitted doc has 0 pages.

### Why this change was made:
- If getTargetSize returned null, the call targetSize.getWidth() would
throw a NullPointerException immediately.
- PDDocument.getNumberOfPages() can be 0 e.g., new PDDocument() or a
loader/factory that produced an empty document for a malformed or
partial upload, or a custom pdfDocumentFactory that creates an empty
document in some error paths.
- Replacing the null return with throw
ExceptionUtils.createInvalidPageSizeException("KEEP"): it fails fast
with a clear error instead of producing an NPE.

<!--
Please provide a summary of the changes, including:

- What was changed
- Why the change was made
- Any challenges encountered

Closes #(issue_number)
-->

---

## 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/devGuide/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/devGuide/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/devGuide/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)

- [x] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing)
for more details.

---------

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
2025-10-11 18:23:09 +01:00
..
common feat(pdf-to-cbr): integrate RAR for CBR output generation (#4626) 2025-10-10 14:10:44 +01:00
core fix(scale): Throw exceptions for invalid page size instead of returning null in getTargetSize method (#4460) 2025-10-11 18:23:09 +01:00
proprietary feat(pdf-to-cbr): integrate RAR for CBR output generation (#4626) 2025-10-10 14:10:44 +01:00
allowed-licenses.json feat(cbr-to-pdf,pdf-to-cbr): add PDF to/from CBR conversion with ebook optimization option (#4581) 2025-10-04 11:15:23 +01:00