Skip to content

Commit

Permalink
Make sure circularity lock does not load any classes during locking a…
Browse files Browse the repository at this point in the history
…nd open visibility.
  • Loading branch information
raphw committed Jul 8, 2024
1 parent cce0ea1 commit 41ce148
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2584,6 +2584,16 @@ class Default implements CircularityLock {
*/
private final ConcurrentMap<Thread, Boolean> threads = new ConcurrentHashMap<Thread, Boolean>();

/**
* Creates a default circularity lock. The constructor invokes all methods that are used by
* the lock to avoid that using this lock triggers class loading under use.
*/
public Default() {
Thread thread = Thread.currentThread();
threads.putIfAbsent(thread, true);
threads.remove(thread);
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -2646,6 +2656,15 @@ public Global(long time, TimeUnit timeUnit) {
lock = new ReentrantLock();
this.time = time;
this.timeUnit = timeUnit;
try {
if (!(time == 0 ? lock.tryLock() : lock.tryLock(time, timeUnit))) {
throw new IllegalStateException();
}
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
return;
}
lock.unlock();
}

/**
Expand Down Expand Up @@ -7006,7 +7025,7 @@ public void remove() {
* during reiteration. For these reasons, this strategy has to be used with care!
* </p>
*/
enum WithSortOrderAssumption implements DiscoveryStrategy {
public enum WithSortOrderAssumption implements DiscoveryStrategy {

/**
* The singleton instance.
Expand Down

0 comments on commit 41ce148

Please sign in to comment.