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

xxyu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/kylin.git


The following commit(s) were added to refs/heads/main by this push:
     new fd4a472e34 minor, fix sonar reported bugs (#1875)
fd4a472e34 is described below

commit fd4a472e348589ea9c6e0c46edcc4b1a06b0ee38
Author: Shaofeng Shi <shaofeng...@apache.org>
AuthorDate: Thu Jun 16 11:03:48 2022 +0800

    minor, fix sonar reported bugs (#1875)
    
    * minor, fix sonar reported bugs
    
    * m
---
 .../apache/kylin/gridtable/GTAggregateScanner.java | 11 +++++------
 .../apache/kylin/rest/util/ControllerSplitter.java |  8 ++++----
 .../HiveColumnCardinalityUpdateJob.java            | 23 +++++++++++++---------
 3 files changed, 23 insertions(+), 19 deletions(-)

diff --git 
a/core-cube/src/main/java/org/apache/kylin/gridtable/GTAggregateScanner.java 
b/core-cube/src/main/java/org/apache/kylin/gridtable/GTAggregateScanner.java
index 59c2455791..ff66805e56 100644
--- a/core-cube/src/main/java/org/apache/kylin/gridtable/GTAggregateScanner.java
+++ b/core-cube/src/main/java/org/apache/kylin/gridtable/GTAggregateScanner.java
@@ -723,12 +723,11 @@ public class GTAggregateScanner implements IGTScanner, 
IGTBypassChecker {
             public void spill() throws IOException {
                 if (spillBuffer == null)
                     return;
-                OutputStream ops = new FileOutputStream(dumpedFile);
-                InputStream ips = new ByteArrayInputStream(spillBuffer);
-                IOUtils.copy(ips, ops);
-                spillBuffer = null;
-                IOUtils.closeQuietly(ips);
-                IOUtils.closeQuietly(ops);
+                try (OutputStream ops = new FileOutputStream(dumpedFile);
+                     InputStream ips = new ByteArrayInputStream(spillBuffer)) {
+                    IOUtils.copy(ips, ops);
+                    spillBuffer = null;
+                }
 
                 logger.info("Spill buffer to disk, location: {}, size = {}.", 
dumpedFile.getAbsolutePath(),
                         dumpedFile.length());
diff --git 
a/server-base/src/main/java/org/apache/kylin/rest/util/ControllerSplitter.java 
b/server-base/src/main/java/org/apache/kylin/rest/util/ControllerSplitter.java
index e043327f9d..c0ca2de527 100644
--- 
a/server-base/src/main/java/org/apache/kylin/rest/util/ControllerSplitter.java
+++ 
b/server-base/src/main/java/org/apache/kylin/rest/util/ControllerSplitter.java
@@ -47,10 +47,10 @@ public class ControllerSplitter {
     private static void chopOff(File f, String annoPtn) throws IOException {
         
         System.out.println("Processing " + f);
-        
-        FileInputStream is = new FileInputStream(f);
-        List<String> lines = IOUtils.readLines(is, "UTF-8");
-        is.close();
+        List<String> lines = new ArrayList<>(0);
+        try (FileInputStream is = new FileInputStream(f)) {
+           lines = IOUtils.readLines(is, "UTF-8");
+        }
         List<String> outLines = new ArrayList<>(lines.size());
         
         boolean del = false;
diff --git 
a/source-hive/src/main/java/org/apache/kylin/source/hive/cardinality/HiveColumnCardinalityUpdateJob.java
 
b/source-hive/src/main/java/org/apache/kylin/source/hive/cardinality/HiveColumnCardinalityUpdateJob.java
index 6593ec6ba5..1712ce5e51 100644
--- 
a/source-hive/src/main/java/org/apache/kylin/source/hive/cardinality/HiveColumnCardinalityUpdateJob.java
+++ 
b/source-hive/src/main/java/org/apache/kylin/source/hive/cardinality/HiveColumnCardinalityUpdateJob.java
@@ -150,16 +150,21 @@ public class HiveColumnCardinalityUpdateJob extends 
AbstractHadoopJob {
 
             CompressionCodec codec = factory.getCodec(item.getPath());
             InputStream stream = null;
-
-            // check if we have a compression codec we need to use
-            if (codec != null) {
-                stream = 
codec.createInputStream(fileSystem.open(item.getPath()));
-            } else {
-                stream = fileSystem.open(item.getPath());
-            }
-
             StringWriter writer = new StringWriter();
-            IOUtils.copy(stream, writer, "UTF-8");
+            try {
+                // check if we have a compression codec we need to use
+                if (codec != null) {
+                    stream = 
codec.createInputStream(fileSystem.open(item.getPath()));
+                } else {
+                    stream = fileSystem.open(item.getPath());
+                }
+
+                IOUtils.copy(stream, writer, "UTF-8");
+            } finally {
+                if (stream != null) {
+                    stream.close();
+                }
+            }
             String raw = writer.toString();
             for (String str : StringUtil.split(raw, "\n")) {
                 results.add(str);

Reply via email to