fix: 修掉命令输出读取的并发访问与缓存流重复关闭

- CmdUtil.StreamCollector 追加内容时与读取方同步,避免 StringBuilder 并发读写
- CacheHelper.getAsString 只在未创建 reader 时单独关闭输入流
This commit is contained in:
tongtong committed 2026-11-21 18:55:24 +08:00
1 parent b80e9f9082
commit 513447ec7a
2 files changed
+8 -7

No files matched your search

@@ -210,14 +210,13 @@ public class CacheHelper {
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "getAsString: " + e.getMessage(), e); Log.e(TAG, "getAsString: " + e.getMessage(), e);
} finally { } finally {
try { if (isr != null) {
if (isr != null) { try {
isr.close(); isr.close();
} catch (IOException e) {
Log.e(TAG, "getAsString: " + e.getMessage(), e);
} }
} catch (IOException e) { } else if (inputStream != null) {
Log.e(TAG, "getAsString: " + e.getMessage(), e);
}
if (inputStream != null) {
try { try {
inputStream.close(); inputStream.close();
} catch (IOException e) { } catch (IOException e) {
@@ -109,7 +109,9 @@ public class CmdUtil {
reader = new BufferedReader(new InputStreamReader(inputStream)); reader = new BufferedReader(new InputStreamReader(inputStream));
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
content.append(line); synchronized (content) {
content.append(line);
}
} }
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "StreamCollector.run: " + e.getMessage(), e); Log.e(TAG, "StreamCollector.run: " + e.getMessage(), e);