Skip to content

fix: fix ArrayStoreException #175

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

Merged
merged 2 commits into from
Jun 2, 2025
Merged

fix: fix ArrayStoreException #175

merged 2 commits into from
Jun 2, 2025

Conversation

javier-godoy
Copy link
Member

@javier-godoy javier-godoy commented Apr 29, 2025

Close #155 and fix #170

Summary by CodeRabbit

  • Refactor
    • Enhanced the representation and handling of grid headers and footers by introducing dedicated classes for clearer and more maintainable export processing.
  • New Features
    • Added new data structures to encapsulate grid header and footer details, improving consistency across CSV, Excel, and DOCX export formats.
  • Style
    • Minor formatting refinements applied for cleaner output in exported Excel files.

@javier-godoy javier-godoy requested review from mlopezFC and paodb April 29, 2025 17:00
Copy link

coderabbitai bot commented Apr 29, 2025

"""

Walkthrough

This change refactors the way grid header and footer information is represented and propagated throughout the grid exporter codebase. It introduces new classes GridHeader<T> and GridFooter<T> implementing a common interface GridHeaderOrFooter<T>, encapsulating header/footer texts and their associated grid columns. The previous use of generic Pair types for headers and footers is replaced by these domain-specific abstractions. Method signatures and internal logic in several exporter classes (BaseStreamResourceWriter, CsvStreamResourceWriter, DocxStreamResourceWriter, and ExcelStreamResourceWriter) are updated accordingly. No changes are made to the overall export logic or output structure.

Changes

Files Change Summary
src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java Refactored getGridHeaders and getGridFooters to return List<GridHeader<T>> and List<GridFooter<T>> respectively instead of pairs; replaced header/footer text extraction logic with new helper methods; removed getHeaderTexts, added getGridHeader.
src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridHeader.java Added final class GridHeader<T> implementing GridHeaderOrFooter<T>, encapsulating a list of header texts and a column with Lombok-generated getters and constructor; overrides getText() to return the first header text.
src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridFooter.java Added final class GridFooter<T> implementing GridHeaderOrFooter<T>, encapsulating a footer text and a column with Lombok-generated getters and constructor; overrides getTexts() to return a singleton list containing the footer text.
src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridHeaderOrFooter.java Added interface GridHeaderOrFooter<T> declaring methods getText(), getTexts(), and getColumn().
src/main/java/com/flowingcode/vaadin/addons/gridexporter/CsvStreamResourceWriter.java Updated CSV export code to replace usage of Pair with GridHeader and GridFooter methods for header and footer text extraction and filtering.
src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java Updated DOCX export code to replace Pair usage with GridHeaderOrFooter interface; generalized method parameter types; replaced calls to pair getters with calls to getText() and getColumn().
src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java Refactored Excel export methods to replace pairs with GridHeader, GridFooter, and GridHeaderOrFooter types; updated method signatures and internal logic accordingly; removed unused imports; minor whitespace cleanup.

Assessment against linked issues

Objective Addressed Explanation
Refactor BaseStreamResourceWriter.getGridHeaders to not return Pair, but a dedicated class (#155)

Possibly related PRs

  • FlowingCode/GridExporterAddon#154: Introduced support for multiple header rows and changed getGridHeaders to return List<Pair<List<String>, Column<T>>>; the current PR further refactors this by introducing GridHeader<T>.

Suggested reviewers

  • mlopezFC
    """
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java (1)

104-121: Well-implemented getGridHeader helper method.

This new method effectively collects all header texts for a given column from all header rows and encapsulates them with the column in a GridHeader instance. The implementation preserves all the previous functionality while providing a cleaner abstraction.

One minor issue: on line 120, the raw type new GridHeader(headerTexts, column) is used without the type parameter. This could be improved for better type safety.

-      return new GridHeader(headerTexts, column);
+      return new GridHeader<T>(headerTexts, column);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e0362ab and 4b4a9ed.

📒 Files selected for processing (5)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java (2 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/CsvStreamResourceWriter.java (1 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java (1 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java (3 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridHeader.java (1 hunks)
🔇 Additional comments (9)
src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridHeader.java (1)

1-15: Good encapsulation of grid header data.

The new GridHeader<T> class provides a well-structured representation of grid headers, replacing the previous use of Pair<List<String>, Column<T>>. The use of Lombok annotations for generating boilerplate code keeps the class concise while providing all necessary functionality.

src/main/java/com/flowingcode/vaadin/addons/gridexporter/CsvStreamResourceWriter.java (1)

64-64: Updated to use the new GridHeader abstraction.

The code now correctly uses GridHeader::getHeaderTexts instead of accessing the left element of pairs, aligning with the refactored return type of getGridHeaders.

src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java (1)

131-134: Properly maps GridHeader to the expected Pair format.

The mapping has been updated to extract the header text and column from the new GridHeader class rather than using pairs directly. The use of header.getHeaderTexts().get(0) assumes that only the first header text is relevant for this context, which matches the previous behavior.

src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java (1)

98-102: Successfully refactored getGridHeaders to return GridHeader objects.

The method now returns a list of GridHeader<T> objects, mapping each column through the new getGridHeader helper method. This provides a more type-safe and semantically clear approach compared to using pairs.

src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java (5)

98-98: LGTM - Method signature refactoring aligns with the new abstraction

The change from receiving Pair objects to GridHeader objects improves code clarity and maintainability. This is consistent with the overall refactor described in the PR.


349-349: Consistent code style improvement

Added appropriate spacing between if and the opening parenthesis.


427-431: Good adapter implementation

The conversion from legacy Pair objects to the new GridHeader abstraction is well implemented. The stream operation creates single-element header lists, maintaining backwards compatibility while moving to the new data structure.


434-434: Method signature update aligns with the new abstraction

Changing the parameter type from the previous List<Pair<...>> to List<GridHeader> improves the method's type safety and readability.


440-442: Clean migration to accessor methods

The code now properly uses GridHeader's getter methods instead of pair accessors, making the intent clearer and improving readability.

@javier-godoy javier-godoy marked this pull request as draft April 29, 2025 17:45
Copy link

@javier-godoy javier-godoy changed the title refactor: refactor getGridHeaders return type fix: fix ArrayStoreException Apr 29, 2025
@javier-godoy
Copy link
Member Author

@coderabbitai review

Copy link

coderabbitai bot commented Apr 29, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridHeader.java (1)

16-18: Consider adding null/empty list check.

The getText() method assumes that texts is never null and contains at least one element. Consider adding a defensive check to prevent potential NullPointerException or IndexOutOfBoundsException.

@Override
public String getText() {
-  return texts.get(0);
+  return texts != null && !texts.isEmpty() ? texts.get(0) : "";
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e1265ca and 05be7e6.

📒 Files selected for processing (7)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java (2 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/CsvStreamResourceWriter.java (1 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java (5 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java (4 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridFooter.java (1 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridHeader.java (1 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridHeaderOrFooter.java (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridHeaderOrFooter.java
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridFooter.java
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/CsvStreamResourceWriter.java
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridHeader.java (1)
src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridFooter.java (1)
  • Getter (8-20)
🔇 Additional comments (5)
src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridHeader.java (1)

8-20: Implementation aligns well with GridFooter class.

The implementation is clean and maintains consistency with the parallel GridFooter class. Both implement the common GridHeaderOrFooter<T> interface while handling their data slightly differently - headers can have multiple texts while footers have a single text.

src/main/java/com/flowingcode/vaadin/addons/gridexporter/DocxStreamResourceWriter.java (4)

130-131: Type refactoring looks good.

The change from using generic Pair objects to domain-specific GridHeader<T> types improves type safety and code clarity.


140-143: Type refactoring looks good.

The change from using generic Pair objects to domain-specific GridFooter<T> types improves type safety and code clarity, consistent with the header implementation.


271-276: Good use of polymorphism.

Updating the method signature to accept List<? extends GridHeaderOrFooter<T>> is a good use of polymorphism that allows the same method to handle both headers and footers, reducing code duplication.


286-302: Method call changes are consistent.

The changes from presumed Pair methods to the new interface methods (header.getText() and header.getColumn().getTextAlign()) are consistently applied throughout the code.

@javier-godoy javier-godoy marked this pull request as ready for review April 29, 2025 18:55
Copy link
Member

@paodb paodb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@paodb paodb merged commit 032461e into master Jun 2, 2025
4 checks passed
@paodb paodb deleted the refactor-155 branch June 2, 2025 18:13
@github-project-automation github-project-automation bot moved this from To Do to Pending release in Flowing Code Addons Jun 2, 2025
@paodb paodb moved this from Pending release to Done in Flowing Code Addons Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

java.lang.ArrayStoreException Refactor BaseStreamResourceWriter return type before public exposure
2 participants