This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-java.git


The following commit(s) were added to refs/heads/main by this push:
     new c8840b010 Avoid FileWriter scheduled task NPE (#205)
c8840b010 is described below

commit c8840b010c9cec3bc2cf3e7b40e7951935ff32e8
Author: huangjikun <[email protected]>
AuthorDate: Sat Jun 11 15:45:33 2022 +0800

    Avoid FileWriter scheduled task NPE (#205)
    
    [Bug] fileOutputStream in FileWriter has been flushed and cleared when 
switching to a new file, which causes NPE.
    
    Fix https://github.com/apache/skywalking/issues/9201
---
 CHANGES.md                                                            | 1 +
 .../org/apache/skywalking/apm/agent/core/logging/core/FileWriter.java | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/CHANGES.md b/CHANGES.md
index 5edd9e0ee..b7dc0c836 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -23,6 +23,7 @@ Release Notes.
 * Fix argument type name of Array in postgresql-8.x-plugin from 
java.lang.String[] to [Ljava.lang.String; 
 * Add type name checking in ArgumentTypeNameMatch and ReturnTypeNameMatch
 * Highlight ArgumentTypeNameMatch and ReturnTypeNameMatch type naming rule in 
docs/en/setup/service-agent/java-agent/Java-Plugin-Development-Guide.md
+* Fix FileWriter scheduled task NPE
 
 #### Documentation
 
diff --git 
a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/FileWriter.java
 
b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/FileWriter.java
index 866bc4f3d..eed675055 100644
--- 
a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/FileWriter.java
+++ 
b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/FileWriter.java
@@ -73,7 +73,9 @@ public class FileWriter implements IWriter {
                                  writeToFile(log + Constants.LINE_SEPARATOR);
                              }
                              try {
-                                 fileOutputStream.flush();
+                                 if (fileOutputStream != null) {
+                                     fileOutputStream.flush();
+                                 }
                              } catch (IOException e) {
                                  e.printStackTrace();
                              }

Reply via email to