Skip to content

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Ludy87
Copy link
Contributor

@Ludy87 Ludy87 commented May 2, 2025

Description of Changes

Please provide a summary of the changes, including:

  • What was changed

    • Updated SignPDFWithCertRequest to use Boolean for showSignature and showLogo, and made pageNumber nullable.
    • In CertSignController:
      • Added an @InitBinder to convert empty multipart fields to null.
      • Extended @PostMapping to consume both multipart/form-data and application/x-www-form-urlencoded.
      • Wrapped pageNumber calculation in a null-check (pageNumber = request.getPageNumber() != null ? request.getPageNumber() - 1 : null).
      • Changed signature-visualization and logo checks to Boolean.TRUE.equals(...) to avoid unboxing NPE.
    • Cleaned up imports and schema annotations in the request model.
  • Why the change was made

    • Prevent a 500 Internal Server Error caused by calling .intValue() on a null pageNumber when showSignature=false (invisible signatures).
    • Ensure that omitting pageNumber doesn’t break clients using the “try it out” swagger UI or curl-based requests.
  • Any challenges encountered

    • Configuring Spring’s data binder to treat empty file inputs as null required a custom PropertyEditorSupport.
    • Balancing backward compatibility with stricter type handling (switching from primitive boolean to boxed Boolean).

Closes #3459


Checklist

General

Documentation

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 for more details.

@Copilot Copilot AI review requested due to automatic review settings May 2, 2025 17:33
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. Bug Something isn't working labels May 2, 2025
@github-actions github-actions bot added Java Pull requests that update Java code Back End Issues related to back-end development API API-related issues or pull requests labels May 2, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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() { ... }

@Ludy87
Copy link
Contributor Author

Ludy87 commented May 2, 2025

/deploypr

@stirlingbot
Copy link
Contributor

stirlingbot bot commented May 2, 2025

🚀 PR Test Deployment

Your PR has been deployed for testing!

🔗 Test URL: http://185.252.234.121:3463
Security Disabled

This deployment will be automatically cleaned up when the PR is closed.

@Ludy87
Copy link
Contributor Author

Ludy87 commented May 2, 2025

🚀 PR Test Deployment

Your PR has been deployed for testing!

🔗 Test URL: http://185.252.234.121:3463 Security Disabled

This deployment will be automatically cleaned up when the PR is closed.

@thepebbler try this PR, the link reflects this PR, you can try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API API-related issues or pull requests Back End Issues related to back-end development Bug Something isn't working Java Pull requests that update Java code size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: API "cert-sign" - 500 - exception due to null pageNumber with invisible signature
1 participant