-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Make static final Set
constants immutable
#13087
Conversation
For the mutable "global" Sets changed Collections.synchronizedSet() to ConcurrentHashMap.newKeySet() for better performance.
# Conflicts: # lucene/CHANGES.txt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR has 2 different types of changes: One is to use ConcurrentHashMap for some synchronized sets, the other one is making stuff final and unmodifiable.
I generally agree, but we could better communicate that in the changes log.
@@ -65,7 +64,7 @@ public final class NativeFSLockFactory extends FSLockFactory { | |||
/** Singleton instance */ | |||
public static final NativeFSLockFactory INSTANCE = new NativeFSLockFactory(); | |||
|
|||
private static final Set<String> LOCK_HELD = Collections.synchronizedSet(new HashSet<String>()); | |||
private static final Set<String> LOCK_HELD = ConcurrentHashMap.newKeySet(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think LOCK_HELP should be Set<Path>
. This would make more sense as it would also be working with different slashes.
I know this isn't related to this cleanup task, but I just have seen it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will open a separate PR for this.
@@ -80,7 +81,7 @@ public abstract class BackwardsCompatibilityTestBase extends LuceneTestCase { | |||
// make sure we never miss a version. | |||
assertTrue("Version: " + version + " missing", binaryVersions.remove(version)); | |||
} | |||
BINARY_SUPPORTED_VERSIONS = binaryVersions; | |||
BINARY_SUPPORTED_VERSIONS = Collections.unmodifiableSet(binaryVersions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We changed that code recently, maybe check also the other Ancient indexes test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestAncientIndicesCompatibility.UNSUPPORTED_INDEXES
is already immutable:
Line 84 in 390c109
UNSUPPORTED_INDEXES = Collections.unmodifiableSet(indices); |
Or did you mean something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok all fine.
|
||
private final Class<C> baseClass; | ||
private final String method; | ||
private final Class<?>[] parameters; | ||
private final ClassValue<Integer> distanceOfClass = | ||
new ClassValue<Integer>() { | ||
new ClassValue<>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is unrelated and does not work with Java 11 (when you subclass on "new" you had to be explicit in former times). I'd like to be explicit here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted
lucene/CHANGES.txt
Outdated
@@ -260,6 +260,8 @@ Improvements | |||
|
|||
* GITHUB#13092: `static final Map` constants have been made immutable (Dmitry Cherniachenko) | |||
|
|||
* GITHUB#13087: Some `static final Set` constants were mutable - rectified. (Dmitry Cherniachenko) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to 9.11
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add the new set impl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
I checked backwards compatibility: Except the scandinavian analyzer everything is tests or implementation private. I think for scandinavian normalizer we need a short note in the changes, because the public set is no longer mutable. Although it would be a downstream bug to actually change it. |
Hi @sabi0, |
Hi @uschindler, |
There seems to be overlap with the latest PR regarding concurrent sets. Maybe revert those changes from this PR. |
fixup! fixup! Make `static final Set` constants immutable
# Conflicts: # lucene/CHANGES.txt
This was a good idea. Thank you. |
Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@@ -65,7 +64,7 @@ public final class NativeFSLockFactory extends FSLockFactory { | |||
/** Singleton instance */ | |||
public static final NativeFSLockFactory INSTANCE = new NativeFSLockFactory(); | |||
|
|||
private static final Set<String> LOCK_HELD = Collections.synchronizedSet(new HashSet<String>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are subtle differences between these two things (synchronized set and a concurrent set). I would leave this change to a separate issue so that it can be assessed separately (I think it's a good idea, but we need to track down all the uses and make sure nothing will break).
@@ -74,14 +73,13 @@ | |||
*/ | |||
public final class VirtualMethod<C> { | |||
|
|||
private static final Set<Method> singletonSet = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, perhaps (or merge with the issue above)?
@@ -61,7 +61,7 @@ | |||
@SuppressForbidden(reason = "We need Unsafe to actually crush :-)") | |||
public class TestSimpleServer extends LuceneTestCase { | |||
|
|||
static final Set<Thread> clientThreads = Collections.synchronizedSet(new HashSet<>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine even here as it only affects one test.
For the mutable "global" Sets changed
Collections.synchronizedSet()
toConcurrentHashMap.newKeySet()
for better performance.