Skip to content

Commit 125ac45

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 9ebe1b3 commit 125ac45

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
@@ -465,19 +465,19 @@ protected void handleMessageInternal(Message<?> message) {
465465
boolean noOutput = true;
466466
try {
467467
lock.lockInterruptibly();
468+
try {
469+
noOutput = processMessageForGroup(message, correlationKey, groupIdUuid, lock);
470+
}
471+
finally {
472+
if (noOutput || !this.releaseLockBeforeSend) {
473+
lock.unlock();
474+
}
475+
}
468476
}
469477
catch (InterruptedException e) {
470478
Thread.currentThread().interrupt();
471479
throw new MessageHandlingException(message, "Interrupted getting lock in the [" + this + ']', e);
472480
}
473-
try {
474-
noOutput = processMessageForGroup(message, correlationKey, groupIdUuid, lock);
475-
}
476-
finally {
477-
if (noOutput || !this.releaseLockBeforeSend) {
478-
lock.unlock();
479-
}
480-
}
481481
}
482482

483483
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
@@ -599,7 +599,7 @@ else if (this.logger.isWarnEnabled()) {
599599
/**
600600
* Retrieves the File instance from the {@link FileHeaders#ORIGINAL_FILE}
601601
* header if available. If the value is not a File instance or a String
602-
* representation of a file path, this will return <code>null</code>.
602+
* representation of a file path, this will return {@code null}.
603603
*/
604604
private File retrieveOriginalFileFromHeader(Message<?> message) {
605605
Object value = message.getHeaders().get(FileHeaders.ORIGINAL_FILE);
@@ -1075,15 +1075,15 @@ private boolean close() {
10751075
catch (IOException e) {
10761076
// ignore
10771077
}
1078+
finally {
1079+
this.lock.unlock();
1080+
}
10781081
return true;
10791082
}
10801083
catch (InterruptedException e1) {
10811084
Thread.currentThread().interrupt();
10821085
return false;
10831086
}
1084-
finally {
1085-
this.lock.unlock();
1086-
}
10871087
}
10881088

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

0 commit comments

Comments
 (0)