Workbook getsheetname logs a warning for exceeding 31 characters #967
+76
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses the issue of silent sheet name truncation caused by the Apache POI 31-character limit (referenced in #966). This limit applies to sheet names in both HSSF (.xls) and XSSF (.xlsx) workbooks.
The primary goal is to strictly enforce the 31-character limit by throwing an
IllegalArgumentExceptionimmediately when a user attempts to retrieve a sheet using an excessively long name. This prevents unexpected behavior (like silent truncation and potentialnullreturns) by forcing users to adhere to the Excel standard.Changes Implemented
getSheet(String name)) for both HSSF and XSSF implementations have been updated to throw anIllegalArgumentExceptionif the provided sheet name exceeds 31 characters. This prevents invalid input from proceeding across both formats.@throws IllegalArgumentExceptionclause.testGetSheetWithNameExceeding31Characters) to useassertThrowsand verify that theIllegalArgumentExceptionis correctly thrown when a name longer than 31 characters is used (ideally with tests covering both HSSF and XSSF contexts).Testing
I have validated these changes locally and included a dedicated test case to verify the new exception behavior. The core functionality of retrieving sheets with valid names remains unchanged across both formats.
Feedback Requested
This change represents a move toward stricter API input validation. Please review the updated Javadoc and the structure of the
IllegalArgumentExceptionfor both the HSSF and XSSF implementations to ensure they align with the project's standards. I am ready to implement any further changes required before merging.