Skip to content

Commit 5ec8913

Browse files
artembilangaryrussell
authored andcommitted
Fix pattern how Lock.unlock() is used
Related to https://build.spring.io/browse/INT-MAIN-84/ The `lock.unlock()` must be called in the `finally` block of the nested `try..catch`, not in the outer which may just fail on `lock.lockInterruptibly()` in which case there is just not going to be anything we can `unlock()` in the end **Cherry-pick to `5.4.x` & `5.3.x`**
1 parent dbc8af9 commit 5ec8913

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractCorrelatingMessageHandler.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -537,19 +537,19 @@ protected void handleMessageInternal(Message<?> message) {
537537
boolean noOutput = true;
538538
try {
539539
lock.lockInterruptibly();
540+
try {
541+
noOutput = processMessageForGroup(message, correlationKey, groupIdUuid, lock);
542+
}
543+
finally {
544+
if (noOutput || !this.releaseLockBeforeSend) {
545+
lock.unlock();
546+
}
547+
}
540548
}
541549
catch (InterruptedException e) {
542550
Thread.currentThread().interrupt();
543551
throw new MessageHandlingException(message, "Interrupted getting lock in the [" + this + ']', e);
544552
}
545-
try {
546-
noOutput = processMessageForGroup(message, correlationKey, groupIdUuid, lock);
547-
}
548-
finally {
549-
if (noOutput || !this.releaseLockBeforeSend) {
550-
lock.unlock();
551-
}
552-
}
553553
}
554554

555555
private boolean processMessageForGroup(Message<?> message, Object correlationKey, UUID groupIdUuid, Lock lock) {

spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ else if (payload instanceof String) {
600600
/**
601601
* Retrieves the File instance from the {@link FileHeaders#ORIGINAL_FILE}
602602
* header if available. If the value is not a File instance or a String
603-
* representation of a file path, this will return <code>null</code>.
603+
* representation of a file path, this will return {@code null}.
604604
*/
605605
private File retrieveOriginalFileFromHeader(Message<?> message) {
606606
Object value = message.getHeaders().get(FileHeaders.ORIGINAL_FILE);
@@ -1076,15 +1076,15 @@ private boolean close() {
10761076
catch (IOException e) {
10771077
// ignore
10781078
}
1079+
finally {
1080+
this.lock.unlock();
1081+
}
10791082
return true;
10801083
}
10811084
catch (InterruptedException e1) {
10821085
Thread.currentThread().interrupt();
10831086
return false;
10841087
}
1085-
finally {
1086-
this.lock.unlock();
1087-
}
10881088
}
10891089

10901090
}
@@ -1175,6 +1175,7 @@ private static final class DefaultFlushPredicate implements MessageFlushPredicat
11751175
@Override
11761176
public boolean shouldFlush(String fileAbsolutePath, long firstWrite, long lastWrite,
11771177
Message<?> triggerMessage) {
1178+
11781179
Pattern pattern;
11791180
if (triggerMessage.getPayload() instanceof String) {
11801181
pattern = Pattern.compile((String) triggerMessage.getPayload());

0 commit comments

Comments
 (0)