parquet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jul...@apache.org
Subject parquet-mr git commit: PARQUET-825: Static analyzer findings (NPEs, resource leaks)
Date Thu, 26 Jan 2017 23:32:34 GMT
Repository: parquet-mr
Updated Branches:
  refs/heads/master 89e0607cf -> f68dbc3ea


PARQUET-825: Static analyzer findings (NPEs, resource leaks)

Some trivial code fixes based on findings on static code analyzer tools (Sonar, Fortify)
@piyushnarang: Sorry, renaming the branch caused the closing of the original PR...

Author: Gabor Szadovszky <gabor.szadovszky@Budapests-MacBook-Pro-8.local>
Author: Gabor Szadovszky <gabor.szadovszky@cloudera.com>

Closes #399 from gszadovszky/PARQUET-825 and squashes the following commits:

68a4764 [Gabor Szadovszky] PARQUET-825 - Static analyzer findings (NPEs, resource leaks)
a689c1c [Gabor Szadovszky] Code fixes related to null checks, exception handling and closing
streams


Project: http://git-wip-us.apache.org/repos/asf/parquet-mr/repo
Commit: http://git-wip-us.apache.org/repos/asf/parquet-mr/commit/f68dbc3e
Tree: http://git-wip-us.apache.org/repos/asf/parquet-mr/tree/f68dbc3e
Diff: http://git-wip-us.apache.org/repos/asf/parquet-mr/diff/f68dbc3e

Branch: refs/heads/master
Commit: f68dbc3ea20230cb14ed3364539ad16e114bcdd9
Parents: 89e0607
Author: Gabor Szadovszky <gabor.szadovszky@Budapests-MacBook-Pro-8.local>
Authored: Thu Jan 26 15:32:28 2017 -0800
Committer: Julien Le Dem <julien@dremio.com>
Committed: Thu Jan 26 15:32:28 2017 -0800

----------------------------------------------------------------------
 .../parquet/io/RecordReaderImplementation.java  |  3 +-
 .../java/org/apache/parquet/glob/GlobNode.java  |  6 +-
 .../ByteBasedBitPackingGenerator.java           | 68 +++++++++---------
 .../bitpacking/IntBasedBitPackingGenerator.java | 74 ++++++++++----------
 .../parquet/version/VersionGenerator.java       |  6 +-
 .../parquet/tools/command/DumpCommand.java      |  2 +-
 .../apache/parquet/tools/command/Registry.java  |  4 +-
 .../parquet/tools/util/PrettyPrintWriter.java   |  4 +-
 8 files changed, 86 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/parquet-mr/blob/f68dbc3e/parquet-column/src/main/java/org/apache/parquet/io/RecordReaderImplementation.java
----------------------------------------------------------------------
diff --git a/parquet-column/src/main/java/org/apache/parquet/io/RecordReaderImplementation.java
b/parquet-column/src/main/java/org/apache/parquet/io/RecordReaderImplementation.java
index af7d4a5..f883c4a 100644
--- a/parquet-column/src/main/java/org/apache/parquet/io/RecordReaderImplementation.java
+++ b/parquet-column/src/main/java/org/apache/parquet/io/RecordReaderImplementation.java
@@ -128,7 +128,8 @@ class RecordReaderImplementation<T> extends RecordReader<T>
{
 //    }
 
     public boolean equals(Case other) {
-      return startLevel == other.startLevel
+      return other != null
+          && startLevel == other.startLevel
           && depth == other.depth
           && nextLevel == other.nextLevel
           && nextState == other.nextState

http://git-wip-us.apache.org/repos/asf/parquet-mr/blob/f68dbc3e/parquet-common/src/main/java/org/apache/parquet/glob/GlobNode.java
----------------------------------------------------------------------
diff --git a/parquet-common/src/main/java/org/apache/parquet/glob/GlobNode.java b/parquet-common/src/main/java/org/apache/parquet/glob/GlobNode.java
index c63c780..35c83dd 100644
--- a/parquet-common/src/main/java/org/apache/parquet/glob/GlobNode.java
+++ b/parquet-common/src/main/java/org/apache/parquet/glob/GlobNode.java
@@ -58,7 +58,7 @@ interface GlobNode {
     @Override
     public boolean equals(Object o) {
       if (this == o) return true;
-      return getClass() == o.getClass() && s.equals(((Atom) o).s);
+      return o != null && getClass() == o.getClass() && s.equals(((Atom)
o).s);
     }
 
     @Override
@@ -97,7 +97,7 @@ interface GlobNode {
     @Override
     public boolean equals(Object o) {
       if (this == o) return true;
-      return getClass() == o.getClass() && children.equals(((OneOf) o).children);
+      return o != null && getClass() == o.getClass() && children.equals(((OneOf)
o).children);
     }
 
     @Override
@@ -136,7 +136,7 @@ interface GlobNode {
     @Override
     public boolean equals(Object o) {
       if (this == o) return true;
-      return getClass() == o.getClass() && children.equals(((OneOf) o).children);
+      return o != null && getClass() == o.getClass() && children.equals(((OneOf)
o).children);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/parquet-mr/blob/f68dbc3e/parquet-generator/src/main/java/org/apache/parquet/encoding/bitpacking/ByteBasedBitPackingGenerator.java
----------------------------------------------------------------------
diff --git a/parquet-generator/src/main/java/org/apache/parquet/encoding/bitpacking/ByteBasedBitPackingGenerator.java
b/parquet-generator/src/main/java/org/apache/parquet/encoding/bitpacking/ByteBasedBitPackingGenerator.java
index b4868e9..6b72592 100644
--- a/parquet-generator/src/main/java/org/apache/parquet/encoding/bitpacking/ByteBasedBitPackingGenerator.java
+++ b/parquet-generator/src/main/java/org/apache/parquet/encoding/bitpacking/ByteBasedBitPackingGenerator.java
@@ -65,42 +65,42 @@ public class ByteBasedBitPackingGenerator {
     if (!file.getParentFile().exists()) {
       file.getParentFile().mkdirs();
     }
-    FileWriter fw = new FileWriter(file);
-    fw.append("package org.apache.parquet.column.values.bitpacking;\n");
-    fw.append("import java.nio.ByteBuffer;\n");
-    fw.append("\n");
-    fw.append("/**\n");
-    if (msbFirst) {
-      fw.append(" * Packs from the Most Significant Bit first\n");
-    } else {
-      fw.append(" * Packs from the Least Significant Bit first\n");
-    }
-    fw.append(" * \n");
-    fw.append(" * @author automatically generated\n");
-    fw.append(" * @see ByteBasedBitPackingGenerator\n");
-    fw.append(" *\n");
-    fw.append(" */\n");
-    fw.append("public abstract class " + className + " {\n");
-    fw.append("\n");
-    fw.append("  private static final BytePacker" + nameSuffix + "[] packers = new BytePacker"
+ nameSuffix + "[" + (maxBits + 1) + "];\n");
-    fw.append("  static {\n");
-    for (int i = 0; i <= maxBits; i++) {
-      fw.append("    packers[" + i + "] = new Packer" + i + "();\n");
-    }
-    fw.append("  }\n");
-    fw.append("\n");
-    fw.append("  public static final BytePacker" + nameSuffix + "Factory factory = new BytePacker"
+ nameSuffix + "Factory() {\n");
-    fw.append("    public BytePacker" + nameSuffix + " newBytePacker" + nameSuffix + "(int
bitWidth) {\n");
-    fw.append("      return packers[bitWidth];\n");
-    fw.append("    }\n");
-    fw.append("  };\n");
-    fw.append("\n");
-    for (int i = 0; i <= maxBits; i++) {
-      generateClass(fw, i, isLong, msbFirst);
+    try (FileWriter fw = new FileWriter(file)) {
+      fw.append("package org.apache.parquet.column.values.bitpacking;\n");
+      fw.append("import java.nio.ByteBuffer;\n");
+      fw.append("\n");
+      fw.append("/**\n");
+      if (msbFirst) {
+        fw.append(" * Packs from the Most Significant Bit first\n");
+      } else {
+        fw.append(" * Packs from the Least Significant Bit first\n");
+      }
+      fw.append(" * \n");
+      fw.append(" * @author automatically generated\n");
+      fw.append(" * @see ByteBasedBitPackingGenerator\n");
+      fw.append(" *\n");
+      fw.append(" */\n");
+      fw.append("public abstract class " + className + " {\n");
       fw.append("\n");
+      fw.append("  private static final BytePacker" + nameSuffix + "[] packers = new BytePacker"
+ nameSuffix + "[" + (maxBits + 1) + "];\n");
+      fw.append("  static {\n");
+      for (int i = 0; i <= maxBits; i++) {
+        fw.append("    packers[" + i + "] = new Packer" + i + "();\n");
+      }
+      fw.append("  }\n");
+      fw.append("\n");
+      fw.append("  public static final BytePacker" + nameSuffix + "Factory factory = new
BytePacker" + nameSuffix + "Factory() {\n");
+      fw.append("    public BytePacker" + nameSuffix + " newBytePacker" + nameSuffix + "(int
bitWidth) {\n");
+      fw.append("      return packers[bitWidth];\n");
+      fw.append("    }\n");
+      fw.append("  };\n");
+      fw.append("\n");
+      for (int i = 0; i <= maxBits; i++) {
+        generateClass(fw, i, isLong, msbFirst);
+        fw.append("\n");
+      }
+      fw.append("}\n");
     }
-    fw.append("}\n");
-    fw.close();
   }
 
   private static void generateClass(FileWriter fw, int bitWidth, boolean isLong, boolean
msbFirst) throws IOException {

http://git-wip-us.apache.org/repos/asf/parquet-mr/blob/f68dbc3e/parquet-generator/src/main/java/org/apache/parquet/encoding/bitpacking/IntBasedBitPackingGenerator.java
----------------------------------------------------------------------
diff --git a/parquet-generator/src/main/java/org/apache/parquet/encoding/bitpacking/IntBasedBitPackingGenerator.java
b/parquet-generator/src/main/java/org/apache/parquet/encoding/bitpacking/IntBasedBitPackingGenerator.java
index e472663..300b84d 100644
--- a/parquet-generator/src/main/java/org/apache/parquet/encoding/bitpacking/IntBasedBitPackingGenerator.java
+++ b/parquet-generator/src/main/java/org/apache/parquet/encoding/bitpacking/IntBasedBitPackingGenerator.java
@@ -56,45 +56,45 @@ public class IntBasedBitPackingGenerator {
     if (!file.getParentFile().exists()) {
       file.getParentFile().mkdirs();
     }
-    FileWriter fw = new FileWriter(file);
-    fw.append("package org.apache.parquet.column.values.bitpacking;\n");
-    fw.append("\n");
-    fw.append("/**\n");
-    fw.append(" * Based on the original implementation at at https://github.com/lemire/JavaFastPFOR/blob/master/src/integercompression/BitPacking.java\n");
-    fw.append(" * Which is released under the\n");
-    fw.append(" * Apache License Version 2.0 http://www.apache.org/licenses/.\n");
-    fw.append(" * By Daniel Lemire, http://lemire.me/en/\n");
-    fw.append(" * \n");
-    fw.append(" * Scheme designed by D. Lemire\n");
-    if (msbFirst) {
-      fw.append(" * Adapted to pack from the Most Significant Bit first\n");
-    }
-    fw.append(" * \n");
-    fw.append(" * @author automatically generated\n");
-    fw.append(" * @see IntBasedBitPackingGenerator\n");
-    fw.append(" *\n");
-    fw.append(" */\n");
-    fw.append("abstract class " + className + " {\n");
-    fw.append("\n");
-    fw.append("  private static final IntPacker[] packers = new IntPacker[32];\n");
-    fw.append("  static {\n");
-    for (int i = 0; i < 32; i++) {
-      fw.append("    packers[" + i + "] = new Packer" + i + "();\n");
-    }
-    fw.append("  }\n");
-    fw.append("\n");
-    fw.append("  public static final IntPackerFactory factory = new IntPackerFactory() {\n");
-    fw.append("    public IntPacker newIntPacker(int bitWidth) {\n");
-    fw.append("      return packers[bitWidth];\n");
-    fw.append("    }\n");
-    fw.append("  };\n");
-    fw.append("\n");
-    for (int i = 0; i < 32; i++) {
-      generateClass(fw, i, msbFirst);
+    try (FileWriter fw = new FileWriter(file)) {
+      fw.append("package org.apache.parquet.column.values.bitpacking;\n");
+      fw.append("\n");
+      fw.append("/**\n");
+      fw.append(" * Based on the original implementation at at https://github.com/lemire/JavaFastPFOR/blob/master/src/integercompression/BitPacking.java\n");
+      fw.append(" * Which is released under the\n");
+      fw.append(" * Apache License Version 2.0 http://www.apache.org/licenses/.\n");
+      fw.append(" * By Daniel Lemire, http://lemire.me/en/\n");
+      fw.append(" * \n");
+      fw.append(" * Scheme designed by D. Lemire\n");
+      if (msbFirst) {
+        fw.append(" * Adapted to pack from the Most Significant Bit first\n");
+      }
+      fw.append(" * \n");
+      fw.append(" * @author automatically generated\n");
+      fw.append(" * @see IntBasedBitPackingGenerator\n");
+      fw.append(" *\n");
+      fw.append(" */\n");
+      fw.append("abstract class " + className + " {\n");
       fw.append("\n");
+      fw.append("  private static final IntPacker[] packers = new IntPacker[32];\n");
+      fw.append("  static {\n");
+      for (int i = 0; i < 32; i++) {
+        fw.append("    packers[" + i + "] = new Packer" + i + "();\n");
+      }
+      fw.append("  }\n");
+      fw.append("\n");
+      fw.append("  public static final IntPackerFactory factory = new IntPackerFactory()
{\n");
+      fw.append("    public IntPacker newIntPacker(int bitWidth) {\n");
+      fw.append("      return packers[bitWidth];\n");
+      fw.append("    }\n");
+      fw.append("  };\n");
+      fw.append("\n");
+      for (int i = 0; i < 32; i++) {
+        generateClass(fw, i, msbFirst);
+        fw.append("\n");
+      }
+      fw.append("}\n");
     }
-    fw.append("}\n");
-    fw.close();
   }
 
   private static void generateClass(FileWriter fw, int bitWidth, boolean msbFirst) throws
IOException {

http://git-wip-us.apache.org/repos/asf/parquet-mr/blob/f68dbc3e/parquet-generator/src/main/java/org/apache/parquet/version/VersionGenerator.java
----------------------------------------------------------------------
diff --git a/parquet-generator/src/main/java/org/apache/parquet/version/VersionGenerator.java
b/parquet-generator/src/main/java/org/apache/parquet/version/VersionGenerator.java
index e0c5e4d..4ad59bf 100644
--- a/parquet-generator/src/main/java/org/apache/parquet/version/VersionGenerator.java
+++ b/parquet-generator/src/main/java/org/apache/parquet/version/VersionGenerator.java
@@ -50,7 +50,11 @@ public class VersionGenerator {
     	throw new IOException("/parquet-version.properties not found");
     }
     Properties props = new Properties();
-    props.load(in);
+    try {
+      props.load(in);
+    } finally {
+      in.close();
+    }
 
     add("package org.apache.parquet;\n" +
         "\n" +

http://git-wip-us.apache.org/repos/asf/parquet-mr/blob/f68dbc3e/parquet-tools/src/main/java/org/apache/parquet/tools/command/DumpCommand.java
----------------------------------------------------------------------
diff --git a/parquet-tools/src/main/java/org/apache/parquet/tools/command/DumpCommand.java
b/parquet-tools/src/main/java/org/apache/parquet/tools/command/DumpCommand.java
index c4ed407..ed84edd 100644
--- a/parquet-tools/src/main/java/org/apache/parquet/tools/command/DumpCommand.java
+++ b/parquet-tools/src/main/java/org/apache/parquet/tools/command/DumpCommand.java
@@ -331,7 +331,7 @@ public class DumpCommand extends ArgsOnlyCommand {
         try {
             CharBuffer buffer = UTF8_DECODER.decode(value.toByteBuffer());
             return buffer.toString();
-        } catch (Throwable th) {
+        } catch (Exception ex) {
         }
 
         return "<bytes...>";

http://git-wip-us.apache.org/repos/asf/parquet-mr/blob/f68dbc3e/parquet-tools/src/main/java/org/apache/parquet/tools/command/Registry.java
----------------------------------------------------------------------
diff --git a/parquet-tools/src/main/java/org/apache/parquet/tools/command/Registry.java b/parquet-tools/src/main/java/org/apache/parquet/tools/command/Registry.java
index a722408..0e69f48 100644
--- a/parquet-tools/src/main/java/org/apache/parquet/tools/command/Registry.java
+++ b/parquet-tools/src/main/java/org/apache/parquet/tools/command/Registry.java
@@ -39,7 +39,7 @@ public final class Registry {
     for (Map.Entry<String,Class<? extends Command>> entry : registry.entrySet())
{
       try {
         results.put(entry.getKey(), entry.getValue().newInstance());
-      } catch (Throwable th) {
+      } catch (Exception ex) {
       }
     }
 
@@ -54,7 +54,7 @@ public final class Registry {
 
     try {
       return clazz.newInstance();
-    } catch (Throwable th) {
+    } catch (Exception ex) {
       return null;
     }
   }

http://git-wip-us.apache.org/repos/asf/parquet-mr/blob/f68dbc3e/parquet-tools/src/main/java/org/apache/parquet/tools/util/PrettyPrintWriter.java
----------------------------------------------------------------------
diff --git a/parquet-tools/src/main/java/org/apache/parquet/tools/util/PrettyPrintWriter.java
b/parquet-tools/src/main/java/org/apache/parquet/tools/util/PrettyPrintWriter.java
index 16fee09..0a12df2 100644
--- a/parquet-tools/src/main/java/org/apache/parquet/tools/util/PrettyPrintWriter.java
+++ b/parquet-tools/src/main/java/org/apache/parquet/tools/util/PrettyPrintWriter.java
@@ -79,7 +79,7 @@ public class PrettyPrintWriter extends PrintWriter {
     if (columns != null && !columns.isEmpty()) {
       try {
         consoleWidth = Integer.parseInt(columns);
-      } catch (Throwable th) {
+      } catch (Exception ex) {
       }
     }
 
@@ -88,7 +88,7 @@ public class PrettyPrintWriter extends PrintWriter {
       try {
         numColors = Integer.parseInt(colors);
         if (numColors < 0) numColors = 0;
-      } catch (Throwable th) {
+      } catch (Exception exa) {
       }
     }
 


Mime
View raw message