Skip to content

Removed deprecated boxed-type constructors from WeakSet impl and tests.#8380

Closed
mbien wants to merge 1 commit intoapache:masterfrom
mbien:weakset-boxing-constructors
Closed

Removed deprecated boxed-type constructors from WeakSet impl and tests.#8380
mbien wants to merge 1 commit intoapache:masterfrom
mbien:weakset-boxing-constructors

Conversation

@mbien
Copy link
Copy Markdown
Member

@mbien mbien commented Apr 1, 2025

  • WeakSet used a Boolean instance as marker object, changed it to boolean[]
  • updated tests to use BigInteger where identity is needed, rest uses valueOf() variants
  • other warning fixes

part of #8257

 - WeakSet used a Boolean instance as marker object, changed it to
   boolean[]
 - updated tests to use BigInteger where identity is needed, rest
   uses valueOf() variants
 - other warning fixes
@mbien mbien added Code cleanup Label for cleanup done on the Netbeans IDE Platform [ci] enable platform tests (platform/*) labels Apr 1, 2025
@mbien mbien added this to the NB26 milestone Apr 1, 2025
@neilcsmith-net
Copy link
Copy Markdown
Member

Is there really anything the breaks using the Boolean constant here? JDK uses Boolean for this use case, and in fact considering that method, I'm curious whether we should deprecate this class at the same time? https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/util/Collections.html#newSetFromMap(java.util.Map)

@mbien
Copy link
Copy Markdown
Member Author

mbien commented Apr 10, 2025

i move this one to NB 27 too.

Is there really anything the breaks using the Boolean constant here?

Boxed type constructors are deprecated for-removal. At some point, they will be gone, see parent issue.

I wouldn't deprecate the class without also rewriting a big part of its usages (as proof of concept) and it is used across the code base. Some modules produce a few thousands compiler warnings already, it would be good to try to reduce that number first before adding more.

Changing the constant here should be harmless since it never leaves the collection - it is a internal marker.

@mbien mbien modified the milestones: NB26, NB27 Apr 10, 2025
@neilcsmith-net
Copy link
Copy Markdown
Member

neilcsmith-net commented Apr 10, 2025

Is there really anything the breaks using the Boolean constant here?

Boxed type constructors are deprecated for-removal. At some point, they will be gone, see parent issue.

I'm aware of the constructor deprecation. The Boolean.TRUE constant is not deprecated.

@mbien
Copy link
Copy Markdown
Member Author

mbien commented Apr 10, 2025

not sure if a shared constant can be used here. would have to check what other instances can hit that code path

@neilcsmith-net
Copy link
Copy Markdown
Member

neilcsmith-net commented Apr 10, 2025

Well, the above linked JDK implementation uses it, anyway.

Point taken on deprecation without rewriting all the usages! It's useful to look at where we have overlap with later JDK APIs, but also no point in changing things without reason.

@mbien
Copy link
Copy Markdown
Member Author

mbien commented Apr 10, 2025

i am thinking about changing it into:

    private static final Object PRESENT = new Object();

since this looks less mysterious, otherwise it makes the impression the value or type is relevant to anything.

@neilcsmith-net
Copy link
Copy Markdown
Member

I was right the first time - https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/Collections.java#L5961 I think using Boolean.TRUE is quite a common pattern for this.

@mbien
Copy link
Copy Markdown
Member Author

mbien commented Apr 10, 2025

now I remember why I didn't change it to an Object instance.

public boolean add(E e) {
boolean[] modified = { false };
m.putIfAbsent(e, modified);
return modified[0];
}

by using a boolean array as value, it becomes consistent with existing usage. The JDK example is nicer since it uses it as payload and compares with null, this is a slightly different implementation - it compares with the marker object and therefore has element-type-mismatch compiler warning suppression across the file.

edit: WeakSet is public API, we should probably deprecate it anyway while taking the hit of the additional compiler warnings across the project
edit2: also assuming I can trust the find usages feature, nothing uses the resize(int) method of this custom collection, this simplifies migration.

@mbien mbien added the do not merge Don't merge this PR, it is not ready or just demonstration purposes. label Apr 10, 2025
@mbien
Copy link
Copy Markdown
Member Author

mbien commented Apr 10, 2025

will close this and replace it with a PR which deprecates WeakSet + refactors all usages to JDK equivalents

@mbien
Copy link
Copy Markdown
Member Author

mbien commented Apr 10, 2025

closing in favor of #8411

@mbien mbien closed this Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Code cleanup Label for cleanup done on the Netbeans IDE do not merge Don't merge this PR, it is not ready or just demonstration purposes. Platform [ci] enable platform tests (platform/*)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants