Skip to content

refine ImmutableCollections class implementations #2484

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 1 commit into
base: master
Choose a base branch
from

Conversation

XenoAmess
Copy link
Contributor

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the Core IT successfully.

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

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

Chesterton's Fence. Do we know why this was here? Maybe it's just old pre Java 1.5 code that we don;t need at all any more. Are there performance impacts?

Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

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

Test are failing

Error: Tests run: 22, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.183 s <<< FAILURE! -- in org.apache.maven.internal.xml.XmlNodeImplTest
Error: org.apache.maven.internal.xml.XmlNodeImplTest.testEqualsIsNullSafe -- Time elapsed: 0.008 s <<< ERROR!
java.lang.NullPointerException
at java.base/java.util.Objects.requireNonNull(Objects.java:209)
at java.base/java.util.ImmutableCollections$MapN.(ImmutableCollections.java:1184)
at java.base/java.util.Map.ofEntries(Map.java:1668)
at java.base/java.util.Map.copyOf(Map.java:1734)
at org.apache.maven.api.xml.ImmutableCollections.copy(ImmutableCollections.java:41)
at org.apache.maven.api.xml.XmlNode$Builder$Impl.(XmlNode.java:471)
at org.apache.maven.api.xml.XmlNode$Builder.build(XmlNode.java:453)
at org.apache.maven.api.xml.XmlNode.newInstance(XmlNode.java:332)
at org.apache.maven.internal.xml.XmlNodeImplTest.testEqualsIsNullSafe(XmlNodeImplTest.java:494)
at java.base/java.lang.reflect.Method.invoke(Method.java:569)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

@XenoAmess
Copy link
Contributor Author

Chesterton's Fence. Do we know why this was here? Maybe it's just old pre Java 1.5 code that we don;t need at all any more. Are there performance impacts?

I know the reason now.
the jdk impl is not null-value-allowable

closing this pr.

@gnodet
Copy link
Contributor

gnodet commented Jun 18, 2025

Chesterton's Fence. Do we know why this was here? Maybe it's just old pre Java 1.5 code that we don;t need at all any more. Are there performance impacts?

I know the reason now. the jdk impl is not null-value-allowable

closing this pr.

The other reason is that Map.copyOf() does not keep input Map ordering.
However, we can remove the read-only Properties which is not used anymore, and I think we can switch to List.empty(), List.of() and List.copyOf() instead of our custom list implementation.
The null-values are not a show-stopper imho, as we can refine the API to now allow nulls, it may just need a few adjustements. However, until we have some kind of SequentialMap.of() in the JDK, we need to keep our own Map implementation.

@gnodet
Copy link
Contributor

gnodet commented Jun 18, 2025

Btw, this duplicates #2363

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants