-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Fix cert-sign API NullPointerException when pageNumber is omitted for invisible signatures #3463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses the NullPointerException occurring when pageNumber is omitted for invisible signatures by improving type handling and null-safety in the cert-sign API. Key changes include:
- Converting the showSignature and showLogo fields from primitives to boxed Booleans and allowing pageNumber to be nullable.
- Adding a custom @InitBinder in CertSignController to convert empty multipart fields to null and updating the endpoint method to consume both multipart form data and urlencoded content.
- Wrapping pageNumber calculation with a null-check and using Boolean.TRUE.equals for null-safe comparisons.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/main/java/stirling/software/SPDF/model/api/security/SignPDFWithCertRequest.java | Updated schema annotations and field types for improved null handling in the request model. |
src/main/java/stirling/software/SPDF/controller/api/security/CertSignController.java | Added a custom property editor, extended POST mapping consumption types, and updated signature/logic checks to prevent NPE. |
Comments suppressed due to low confidence (1)
src/main/java/stirling/software/SPDF/controller/api/security/CertSignController.java:90
- [nitpick] Consider adding a clarifying comment on the custom PropertyEditorSupport registration to explain that any provided text for a MultipartFile is intentionally treated as null. This will help future maintainers understand the rationale behind this configuration.
binder.registerCustomEditor( MultipartFile.class, new PropertyEditorSupport() { ... }
src/main/java/stirling/software/SPDF/controller/api/security/CertSignController.java
Show resolved
Hide resolved
/deploypr |
🚀 PR Test DeploymentYour PR has been deployed for testing! 🔗 Test URL: http://185.252.234.121:3463 This deployment will be automatically cleaned up when the PR is closed. |
@thepebbler try this PR, the link reflects this PR, you can try |
Description of Changes
Please provide a summary of the changes, including:
What was changed
SignPDFWithCertRequest
to useBoolean
forshowSignature
andshowLogo
, and madepageNumber
nullable.CertSignController
:@InitBinder
to convert empty multipart fields tonull
.@PostMapping
to consume bothmultipart/form-data
andapplication/x-www-form-urlencoded
.pageNumber
calculation in a null-check (pageNumber = request.getPageNumber() != null ? request.getPageNumber() - 1 : null
).Boolean.TRUE.equals(...)
to avoid unboxing NPE.Why the change was made
.intValue()
on a nullpageNumber
whenshowSignature=false
(invisible signatures).pageNumber
doesn’t break clients using the “try it out” swagger UI orcurl
-based requests.Any challenges encountered
null
required a customPropertyEditorSupport
.boolean
to boxedBoolean
).Closes #3459
Checklist
General
Documentation
UI Changes (if applicable)
Testing (if applicable)