Skip to content

Commit 6ef823b

Browse files
authored
[release/3.8] 修复 ManagedProcess#getLines 完成后不会解除锁定的问题 (#4982)
#4913
1 parent d577e1f commit 6ef823b

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/ManagedProcess.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,19 @@ public Map<String, Object> getProperties() {
113113
*/
114114
public List<String> getLines(Predicate<String> lineFilter) {
115115
lock.lock();
116-
117-
if (lineFilter == null)
118-
return List.copyOf(lines);
119-
120-
ArrayList<String> res = new ArrayList<>();
121-
for (String line : this.lines) {
122-
if (lineFilter.test(line))
123-
res.add(line);
116+
try {
117+
if (lineFilter == null)
118+
return List.copyOf(lines);
119+
120+
ArrayList<String> res = new ArrayList<>();
121+
for (String line : this.lines) {
122+
if (lineFilter.test(line))
123+
res.add(line);
124+
}
125+
return Collections.unmodifiableList(res);
126+
} finally {
127+
lock.unlock();
124128
}
125-
return Collections.unmodifiableList(res);
126129
}
127130

128131
public void addLine(String line) {

0 commit comments

Comments
 (0)