Skip to content

Commit 1e437b7

Browse files
committed
Fix lock() position
1 parent 712171c commit 1e437b7

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,8 @@ private Environment(final PropertySource propertySource) {
538538
}
539539

540540
private void addPropertySource(final PropertySource propertySource) {
541+
sourceWriteLock.lock();
541542
try {
542-
sourceWriteLock.lock();
543543
if (!sources.contains(propertySource)) {
544544
sources.add(propertySource);
545545
sources.sort(Comparator.INSTANCE);
@@ -550,8 +550,8 @@ private void addPropertySource(final PropertySource propertySource) {
550550
}
551551

552552
private void removePropertySource(final PropertySource propertySource) {
553+
sourceWriteLock.lock();
553554
try {
554-
sourceWriteLock.lock();
555555
sources.remove(propertySource);
556556
} finally {
557557
sourceWriteLock.unlock();
@@ -561,8 +561,8 @@ private void removePropertySource(final PropertySource propertySource) {
561561
private void reload() {
562562
literal.clear();
563563
tokenized.clear();
564+
sourceWriteLock.lock();
564565
try {
565-
sourceWriteLock.lock();
566566
// 1. Collects all property keys from enumerable sources.
567567
final Set<String> keys = new HashSet<>();
568568
sources.stream().map(PropertySource::getPropertyNames).forEach(keys::addAll);
@@ -598,8 +598,8 @@ private String get(final String key) {
598598
}
599599
final List<CharSequence> tokens = PropertySource.Util.tokenize(key);
600600
final boolean hasTokens = !tokens.isEmpty();
601+
sourceReadLock.lock();
601602
try {
602-
sourceReadLock.lock();
603603
for (final PropertySource source : sources) {
604604
if (hasTokens) {
605605
final String normalKey = Objects.toString(source.getNormalForm(tokens), null);
@@ -637,8 +637,8 @@ private String sourceGetProperty(final PropertySource source, final String key)
637637

638638
private boolean containsKey(final String key) {
639639
final List<CharSequence> tokens = PropertySource.Util.tokenize(key);
640+
sourceReadLock.lock();
640641
try {
641-
sourceReadLock.lock();
642642
return literal.containsKey(key)
643643
|| tokenized.containsKey(tokens)
644644
|| sources.stream().anyMatch(s -> {

0 commit comments

Comments
 (0)