Skip to content
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

Stop using references to collections #458

Merged
merged 6 commits into from
Dec 30, 2024
Merged

Stop using references to collections #458

merged 6 commits into from
Dec 30, 2024

Conversation

jodastephen
Copy link
Member

@jodastephen jodastephen commented Dec 30, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced serialization support for generic interface collections.
    • Improved binary format compatibility and performance.
  • Changes

    • Updated handling of collection references in serialization.
    • Introduced a new method for testing generic interface collections.
    • Added a new action in release notes detailing changes in binary format behaviour.
  • Compatibility

    • Version 3.0.0-RC1 introduces potential changes in binary format deduplication.
    • Previous format remains parseable.

The release focuses on improving serialization mechanisms and testing coverage for complex collection types.

Will Nicholson and others added 5 commits October 20, 2020 14:27
Types with collections are a bit hairy, what if it's first read as Set but later we serialize the same thing as SortedSet? Can't reuse the original value but instead need a copy constructor, and that's a lot of effort to code
Copy link

coderabbitai bot commented Dec 30, 2024

📝 Walkthrough

Walkthrough

The pull request introduces changes across multiple files in the Joda Beans project, focusing on serialization and reference handling. The modifications include updates to the changes documentation, improvements in binary reference processing, and additions to test coverage for serialization of generic interface collections. The changes primarily target version 3.0.0-RC1 and address compatibility, performance, and serialization mechanisms.

Changes

File Change Summary
src/changes/changes.xml Added new action for version 3.0.0-RC1 describing changes in binary format reference handling and collection deduplication; updated actions to fix typos.
src/main/java/org/joda/beans/ser/bin/BeanReferences.java Simplified reference finding logic and added handling for non-Bean objects with parent iterators.
src/test/java/org/joda/beans/ser/SerTestHelper.java Added testGenericInterfacesCollections() method to support testing of generic interface collections.
src/test/java/org/joda/beans/ser/bin/TestSerializeReferencingBin.java Introduced new test method test_writeJodaConvertInterfaceCollections() to verify serialization of generic interface collections.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @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.

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.

@jodastephen jodastephen changed the title Pr 230 Stop using references to collections Dec 30, 2024
@jodastephen
Copy link
Member Author

This replaces PR #230

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 (3)
src/main/java/org/joda/beans/ser/bin/BeanReferences.java (2)

137-143: Confirm correctness of the early return path.
The current logic means if objects.compute(...) returns a value above 1, the code may skip deeper bean-level checks, but still processes collections when !(base instanceof Bean). Verify that this early return does not miss referencing repeated beans, as it might interfere with future reference resolution in deeply nested structures.


173-173: Clarify the comment or remove if self-explanatory.
The code comment at line 173 (“shouldn't try and reuse references to collections”) duplicates the earlier comment. Consider removing or consolidating for clarity.

src/changes/changes.xml (1)

37-41: Confirm wording accuracy.
The statement "The old format cam still be parsed successfully" at line 40 contains a small typo (“cam” should likely be “can”).

- The old format cam still be parsed successfully.
+ The old format can still be parsed successfully.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e1e9b9e and 0aefb40.

📒 Files selected for processing (4)
  • src/changes/changes.xml (1 hunks)
  • src/main/java/org/joda/beans/ser/bin/BeanReferences.java (2 hunks)
  • src/test/java/org/joda/beans/ser/SerTestHelper.java (2 hunks)
  • src/test/java/org/joda/beans/ser/bin/TestSerializeReferencingBin.java (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
src/test/java/org/joda/beans/ser/bin/TestSerializeReferencingBin.java (2)

Pattern **/*.java: - Review code using Java 21 standards, taking into account the rules defined by src/main/checkstyle/checkstyle.xml.

  • Validate that code indentation uses spaces, not tabs, with an indent of multiple of 4.
  • Validate that immutable local variables are not annotated with final unless the variable is required for use in an inner class.
  • Favour use of var keyword for type declarations. var may also be used when the value is a cast null.
  • Use a coding standard where multi-line expressions have operators and tenary separators at the end of line.
  • Propose changes that only use the Java 21 API, not the API of Guava.
  • The pattern matching instanceof expression safely handles null, returning false.

Pattern **/test/java/**/*.java: For test code, focus on:

  • Correctness of test assertions
  • Test coverage of edge cases
  • Clear test naming and documentation
  • Encourage test methods to be package-scoped where possible
  • Be more lenient with code style and minor optimisations
src/test/java/org/joda/beans/ser/SerTestHelper.java (2)

Pattern **/*.java: - Review code using Java 21 standards, taking into account the rules defined by src/main/checkstyle/checkstyle.xml.

  • Validate that code indentation uses spaces, not tabs, with an indent of multiple of 4.
  • Validate that immutable local variables are not annotated with final unless the variable is required for use in an inner class.
  • Favour use of var keyword for type declarations. var may also be used when the value is a cast null.
  • Use a coding standard where multi-line expressions have operators and tenary separators at the end of line.
  • Propose changes that only use the Java 21 API, not the API of Guava.
  • The pattern matching instanceof expression safely handles null, returning false.

Pattern **/test/java/**/*.java: For test code, focus on:

  • Correctness of test assertions
  • Test coverage of edge cases
  • Clear test naming and documentation
  • Encourage test methods to be package-scoped where possible
  • Be more lenient with code style and minor optimisations
src/main/java/org/joda/beans/ser/bin/BeanReferences.java (2)

Pattern **/*.java: - Review code using Java 21 standards, taking into account the rules defined by src/main/checkstyle/checkstyle.xml.

  • Validate that code indentation uses spaces, not tabs, with an indent of multiple of 4.
  • Validate that immutable local variables are not annotated with final unless the variable is required for use in an inner class.
  • Favour use of var keyword for type declarations. var may also be used when the value is a cast null.
  • Use a coding standard where multi-line expressions have operators and tenary separators at the end of line.
  • Propose changes that only use the Java 21 API, not the API of Guava.
  • The pattern matching instanceof expression safely handles null, returning false.

Pattern **/main/java/**/*.java: - This project is mature and must provide a stable backwards-compatible public Java API.

  • In the 'Walkthrough' section, you must always provide a list of up to 25 changes to the public Java API that will affect end users.
    If there are no changes, you must explicitly state that there are no changes to the public Java API in this PR.
    The public Java API is defined as public and protected methods on public classes, plus the file module-info.java.
    Provide the list by deeply analysing code flow, which incudes analysing code flow through private methods and calls to Guava and Java 21.
    Changes to be reported on include:
    • New or removed methods in the public Java API
    • Changes to method return types or parameter types in the public Java API
    • Changes to method behaviour in the public Java API that might affect consumers
  • This project uses System.out.println instead of logging
  • This project tends to prefer for loops to streams for performance reasons, however either form is acceptable.
    Do not make suggestions to change between streams and for loops or vice versa.
🔇 Additional comments (3)
src/main/java/org/joda/beans/ser/bin/BeanReferences.java (1)

136-137: Validate potential concurrency usage.
If this code could be called concurrently, objects might need concurrent access handling. Currently, it relies on being called serially, which is acceptable if guaranteed. Otherwise, consider a thread-safe approach.

src/test/java/org/joda/beans/ser/bin/TestSerializeReferencingBin.java (1)

133-143: Test coverage looks good.
This new test covers serialising/deserialising collections of Joda-Convert-based interfaces. It exercises the changes in BeanReferences and ensures references to collections are handled properly. The test appears correct and complete.

src/test/java/org/joda/beans/ser/SerTestHelper.java (1)

261-271: Ensure coverage for nested structures.
The new method testGenericInterfacesCollections covers various collection implementations. Ensure that the returned bean is exercised by multiple tests, especially regarding handling of set/hash collisions and references.

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/test/java/org/joda/beans/ser/SerTestHelper.java (1)

261-270: The implementation looks good but could benefit from documentation and additional test cases.

The method effectively tests serialisation of various collection types, including both JDK and Guava implementations. However, consider these improvements:

  1. Add Javadoc explaining the method's purpose and expected usage
  2. Include test cases for:
    • Empty collections
    • Collections containing null values
    • Edge cases like collections with a single element

Here's a suggested enhancement:

+    /**
+     * Creates test data for serialising generic collections of various types.
+     * This includes both JDK collections (ArrayList, HashSet, TreeSet) and
+     * Guava collections (ImmutableList, ImmutableMap).
+     *
+     * @return the test data, not null
+     */
     public static ImmGenericCollections<Object> testGenericInterfacesCollections() {
         return ImmGenericCollections.builder()
                 .map(ImmutableMap.of(
                         "First", Arrays.asList("A", "B"),
                         "First1", ImmutableList.of("A", "B"),
                         "Third1", new TreeSet<>(ImmutableList.of("A", "B")),
                         "Third", new HashSet<>(Arrays.asList("A", "B")),
+                        "Empty", ImmutableList.of(),
+                        "WithNull", Arrays.asList("A", null, "B"),
                         "Second", testCollections(true)))
                 .build();
     }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0aefb40 and bfb9727.

📒 Files selected for processing (3)
  • src/changes/changes.xml (2 hunks)
  • src/main/java/org/joda/beans/ser/bin/BeanReferences.java (2 hunks)
  • src/test/java/org/joda/beans/ser/SerTestHelper.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/java/org/joda/beans/ser/bin/BeanReferences.java
  • src/changes/changes.xml
🧰 Additional context used
📓 Path-based instructions (1)
src/test/java/org/joda/beans/ser/SerTestHelper.java (2)

Pattern **/*.java: - Review code using Java 21 standards, taking into account the rules defined by src/main/checkstyle/checkstyle.xml.

  • Validate that code indentation uses spaces, not tabs, with an indent of multiple of 4.
  • Validate that immutable local variables are not annotated with final unless the variable is required for use in an inner class.
  • Favour use of var keyword for type declarations. var may also be used when the value is a cast null.
  • Use a coding standard where multi-line expressions have operators and tenary separators at the end of line.
  • Propose changes that only use the Java 21 API, not the API of Guava.
  • The pattern matching instanceof expression safely handles null, returning false.

Pattern **/test/java/**/*.java: For test code, focus on:

  • Correctness of test assertions
  • Test coverage of edge cases
  • Clear test naming and documentation
  • Encourage test methods to be package-scoped where possible
  • Be more lenient with code style and minor optimisations
🔇 Additional comments (1)
src/test/java/org/joda/beans/ser/SerTestHelper.java (1)

22-22: LGTM! The new imports are properly organised.

The added imports for HashSet and TreeSet are correctly placed in alphabetical order and are required for the new test method.

Also applies to: 27-27

@jodastephen jodastephen merged commit 6e92cc2 into main Dec 30, 2024
5 checks passed
@jodastephen jodastephen deleted the pr-230 branch December 30, 2024 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant