Stirling-Tools / Stirling-PDF

#1 Locally hosted web application that allows you to perform various operations on PDF files
https://stirlingpdf.com
MIT License
46.13k stars 3.75k forks source link

[Bug]: Unchecked Checkboxes for Include Metadata and Allow Duplicates Cause Null Pointer Exception in /split-pdf-by-chapters Feature #2233

Open MaratheHarshad opened 9 hours ago

MaratheHarshad commented 9 hours ago

Installation Method

None

The Problem

Description:

Currently, in the /split-pdf-by-chapters feature, the includeMetadata and allowDuplicates checkboxes are not correctly submitting true or false values based on the user's selection. When the checkboxes are left unchecked, the backend receives null instead of a boolean false, which results in a NullPointerException.

Feature URL: https://stirlingpdf.io/split-pdf-by-chapters

Steps to Reproduce:

  1. Go to the /split-pdf-by-chapters feature page.
  2. Leave the Include Metadata and Allow Duplicates checkboxes unchecked.
  3. Submit the form.
  4. Notice that a NullPointerException occurs on the backend due to null values for these fields.

Expected Behavior:

The backend should receive true if the checkbox is checked and false if it’s unchecked. The form should correctly handle boolean values for these checkboxes without causing errors.

Screenshots:

image

Version of Stirling-PDF

0.32.0

Last Working Version of Stirling-PDF

No response

Page Where the Problem Occurred

https://stirlingpdf.io/split-pdf-by-chapters

Docker Configuration

No response

Relevant Log Output

No response

Additional Information

No response

Browsers Affected

No response

No Duplicate of the Issue

dosubot[bot] commented 9 hours ago

To resolve the NullPointerException caused by unchecked checkboxes for "Include Metadata" and "Allow Duplicates" in the /split-pdf-by-chapters feature, you should ensure that the backend receives boolean false instead of null. This can be achieved by setting default values for these fields in the SplitPdfByChaptersRequest class. Here's how you can modify the class:

@Data
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
class SplitPdfByChaptersRequest {
    private MultipartFile fileInput;
    private Integer bookmarkLevel;
    private boolean includeMetadata = false; // Default to false
    private boolean allowDuplicates = false; // Default to false
}

By setting default values for includeMetadata and allowDuplicates to false, the backend will receive false when the checkboxes are unchecked, preventing the NullPointerException [1]. Additionally, ensure that the frontend form is correctly configured to send false when these checkboxes are unchecked [2].

To continue talking to Dosu, mention @dosu.