[ https://issues.apache.org/jira/browse/KYLIN-3597?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16714741#comment-16714741 ]
ASF GitHub Bot commented on KYLIN-3597: --------------------------------------- shaofengshi closed pull request #379: KYLIN-3597 fix sonar issues URL: https://github.com/apache/kylin/pull/379 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/core-common/src/main/java/org/apache/kylin/common/BackwardCompatibilityConfig.java b/core-common/src/main/java/org/apache/kylin/common/BackwardCompatibilityConfig.java index aeb7636059..751d2f7da6 100644 --- a/core-common/src/main/java/org/apache/kylin/common/BackwardCompatibilityConfig.java +++ b/core-common/src/main/java/org/apache/kylin/common/BackwardCompatibilityConfig.java @@ -144,26 +144,21 @@ private static void generateFindAndReplaceScript(String kylinRepoPath, String ou BackwardCompatibilityConfig bcc = new BackwardCompatibilityConfig(); File repoDir = new File(kylinRepoPath).getCanonicalFile(); File outputDir = new File(outputPath).getCanonicalFile(); - PrintWriter out = null; // generate sed file File sedFile = new File(outputDir, "upgrade-old-config.sed"); - try { - out = new PrintWriter(sedFile, "UTF-8"); + try (PrintWriter out = new PrintWriter(sedFile, "UTF-8")) { for (Entry<String, String> e : bcc.old2new.entrySet()) { out.println("s/" + quote(e.getKey()) + "/" + e.getValue() + "/g"); } for (Entry<String, String> e : bcc.old2newPrefix.entrySet()) { out.println("s/" + quote(e.getKey()) + "/" + e.getValue() + "/g"); } - } finally { - IOUtils.closeQuietly(out); } // generate sh file File shFile = new File(outputDir, "upgrade-old-config.sh"); - try { - out = new PrintWriter(shFile, "UTF-8"); + try (PrintWriter out = new PrintWriter(shFile, "UTF-8")) { out.println("#!/bin/bash"); Stack<File> stack = new Stack<>(); stack.push(repoDir); @@ -179,8 +174,6 @@ private static void generateFindAndReplaceScript(String kylinRepoPath, String ou out.println("sed -i -f upgrade-old-config.sed " + f.getAbsolutePath()); } } - } finally { - IOUtils.closeQuietly(out); } System.out.println("Files generated:"); diff --git a/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java b/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java index 4a86b762f3..4db1748910 100644 --- a/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java +++ b/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java @@ -50,6 +50,7 @@ public class KylinConfig extends KylinConfigBase { private static final long serialVersionUID = 1L; private static final Logger logger = LoggerFactory.getLogger(KylinConfig.class); + private static final String METADATA_URI_PREFIX = "Metadata uri : "; /** * Kylin properties file name @@ -192,20 +193,20 @@ private static UriType decideUriType(String metaUri) { return UriType.PROPERTIES_FILE; } else { throw new IllegalStateException( - "Metadata uri : " + metaUri + " is a local file but not kylin.properties"); + METADATA_URI_PREFIX + metaUri + " is a local file but not kylin.properties"); } } else { throw new IllegalStateException( - "Metadata uri : " + metaUri + " looks like a file but it's neither a file nor a directory"); + METADATA_URI_PREFIX + metaUri + " looks like a file but it's neither a file nor a directory"); } } else { if (RestClient.matchFullRestPattern(metaUri)) return UriType.REST_ADDR; else - throw new IllegalStateException("Metadata uri : " + metaUri + " is not a valid REST URI address"); + throw new IllegalStateException(METADATA_URI_PREFIX + metaUri + " is not a valid REST URI address"); } } catch (Exception e) { - throw new IllegalStateException("Metadata uri : " + metaUri + " is not recognized", e); + throw new IllegalStateException(METADATA_URI_PREFIX + metaUri + " is not recognized", e); } } @@ -393,9 +394,8 @@ private static OrderedProperties buildSiteOrderedProps() { */ private static void loadPropertiesFromInputStream(InputStream inputStream, OrderedProperties properties) { Preconditions.checkNotNull(properties); - BufferedReader confReader = null; - try { - confReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); + + try (BufferedReader confReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"))) { OrderedProperties temp = new OrderedProperties(); temp.load(confReader); temp = BCC.check(temp); @@ -403,8 +403,6 @@ private static void loadPropertiesFromInputStream(InputStream inputStream, Order properties.putAll(temp); } catch (Exception e) { throw new RuntimeException(e); - } finally { - IOUtils.closeQuietly(confReader); } } @@ -521,12 +519,8 @@ public String exportToString(Collection<String> propertyKeys) throws IOException } public void exportToFile(File file) throws IOException { - FileOutputStream fos = null; - try { - fos = new FileOutputStream(file); + try (FileOutputStream fos = new FileOutputStream(file)) { getAllProperties().store(fos, file.getAbsolutePath()); - } finally { - IOUtils.closeQuietly(fos); } } ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Fix sonar reported static code issues > ------------------------------------- > > Key: KYLIN-3597 > URL: https://issues.apache.org/jira/browse/KYLIN-3597 > Project: Kylin > Issue Type: Improvement > Components: Others > Reporter: Shaofeng SHI > Priority: Major > Fix For: v2.6.0 > > -- This message was sent by Atlassian JIRA (v7.6.3#76005)