-
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
Changes from 3 commits
7d00c50
1b2ab16
f5ace6f
b7dbc2e
ac1d292
acaea13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -26,6 +26,7 @@ | |||
import java.nio.file.Paths; | ||||
import java.text.ParseException; | ||||
import java.util.ArrayList; | ||||
import java.util.Collections; | ||||
import java.util.HashSet; | ||||
import java.util.Iterator; | ||||
import java.util.List; | ||||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
Line 84 in 390c109
Or did you mean something else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok all fine. |
||||
} | ||||
|
||||
/** | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,8 @@ | |
import java.nio.file.StandardOpenOption; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
import java.nio.file.attribute.FileTime; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import org.apache.lucene.util.IOUtils; | ||
|
||
/** | ||
|
@@ -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 commentThe 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). |
||
private static final Set<String> LOCK_HELD = ConcurrentHashMap.newKeySet(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think LOCK_HELP should be 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 commentThe reason will be displayed to describe this comment to others. Learn more. I will open a separate PR for this. |
||
|
||
private NativeFSLockFactory() {} | ||
|
||
|
@@ -127,7 +126,7 @@ protected Lock obtainFSLock(FSDirectory dir, String lockName) throws IOException | |
} | ||
} | ||
|
||
private static final void clearLockHeld(Path path) throws IOException { | ||
private static void clearLockHeld(Path path) throws IOException { | ||
boolean remove = LOCK_HELD.remove(path.toString()); | ||
if (remove == false) { | ||
throw new AlreadyClosedException("Lock path was cleared but never marked as held: " + path); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,15 +19,14 @@ | |
import java.lang.reflect.Method; | ||
import java.security.AccessController; | ||
import java.security.PrivilegedAction; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* A utility for keeping backwards compatibility on previously abstract methods (or similar | ||
* replacements). | ||
* | ||
* <p>Before the replacement method can be made abstract, the old method must kept deprecated. If | ||
* <p>Before the replacement method can be made abstract, the old method must be kept deprecated. If | ||
* somebody still overrides the deprecated method in a non-final class, you must keep track, of this | ||
* and maybe delegate to the old method in the subclass. The cost of reflection is minimized by the | ||
* following usage of this class: | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Same here, perhaps (or merge with the issue above)? |
||
Collections.synchronizedSet(new HashSet<Method>()); | ||
private static final Set<Method> singletonSet = ConcurrentHashMap.newKeySet(); | ||
|
||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Reverted |
||
@Override | ||
protected Integer computeValue(Class<?> subclazz) { | ||
return Integer.valueOf(reflectImplementationDistance(subclazz)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,12 +29,12 @@ | |
import java.net.SocketException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import org.apache.lucene.store.DataInput; | ||
import org.apache.lucene.store.DataOutput; | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Seems fine even here as it only affects one test. |
||
static final Set<Thread> clientThreads = ConcurrentHashMap.newKeySet(); | ||
static final AtomicBoolean stop = new AtomicBoolean(); | ||
|
||
/** Handles one client connection */ | ||
|
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