提交 c86312f3 编写于 作者: C caoyixiong 提交者: wu-sheng

close inputStream safety & FIX NPE in AlarmService (#1661)

* close inputStream safety

* FIX NPE in AlarmService
上级 e52715b7
......@@ -19,6 +19,7 @@
package org.apache.skywalking.apm.collector.analysis.segment.parser.provider.buffer;
import com.google.protobuf.CodedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
......@@ -26,6 +27,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.apache.skywalking.apm.collector.analysis.segment.parser.define.service.ISegmentParseService;
import org.apache.skywalking.apm.collector.analysis.segment.parser.provider.parser.SegmentParse;
import org.apache.skywalking.apm.collector.analysis.segment.parser.provider.parser.SegmentParserListenerManager;
......@@ -148,13 +150,20 @@ public enum SegmentBufferReader {
OffsetManager.INSTANCE.setReadOffset(readFileOffset);
}
inputStream.close();
if (!writeFileName.equals(readFile.getName())) {
readFile.delete();
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
return false;
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
}
return true;
}
......
......@@ -175,7 +175,7 @@ public class AlarmService {
private String buildServerName(String osInfoJson) {
JsonObject osInfo = gson.fromJson(osInfoJson, JsonObject.class);
String serverName = Const.UNKNOWN;
if (osInfo.has("hostName")) {
if (osInfo != null && osInfo.has("hostName")) {
serverName = osInfo.get("hostName").getAsString();
}
return serverName;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册