Commit c86312f3 authored by caoyixiong's avatar caoyixiong Committed by 吴晟
Browse files

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

* close inputStream safety

* FIX NPE in AlarmService
parent e52715b7
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -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;
    }
+1 −1
Original line number Diff line number Diff line
@@ -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;