]> source.dussan.org Git - poi.git/commitdiff
Sonar fixes
authorAndreas Beeker <kiwiwings@apache.org>
Fri, 24 Jun 2016 22:04:12 +0000 (22:04 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Fri, 24 Jun 2016 22:04:12 +0000 (22:04 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1750171 13f79535-47bb-0310-9956-ffa450edef68

12 files changed:
src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java
src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java
src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java
src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java
src/java/org/apache/poi/hssf/record/cf/FontFormatting.java
src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java
src/java/org/apache/poi/hssf/record/chart/SeriesListRecord.java
src/java/org/apache/poi/hssf/record/common/ExtendedColor.java
src/java/org/apache/poi/hssf/record/crypto/Biff8RC4Key.java
src/java/org/apache/poi/hssf/usermodel/DVConstraint.java
src/scratchpad/src/org/apache/poi/hwpf/model/FFData.java

index 9294b5babc067f17b7587583266b30b1b045ddd3..27f168e31eebd0aed9f9e4a1e67c1f87bad635a3 100644 (file)
@@ -30,6 +30,7 @@ import org.apache.poi.hssf.usermodel.HSSFRichTextString;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.BorderStyle;
 import org.apache.poi.ss.util.CellRangeAddress;
 
 /**
@@ -69,13 +70,13 @@ public final class HSSFReadWrite {
 
                f.setFontHeightInPoints((short) 12);
                f.setColor((short) 0xA);
-               f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
+               f.setBold(true);
                f2.setFontHeightInPoints((short) 10);
                f2.setColor((short) 0xf);
-               f2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
+               f2.setBold(true);
                cs.setFont(f);
                cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)"));
-               cs2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
+               cs2.setBorderBottom(BorderStyle.THIN);
                cs2.setFillPattern((short) 1); // fill w fg
                cs2.setFillForegroundColor((short) 0xA);
                cs2.setFont(f2);
@@ -107,7 +108,7 @@ public final class HSSFReadWrite {
                rownum++;
                rownum++;
                HSSFRow r = s.createRow(rownum);
-               cs3.setBorderBottom(HSSFCellStyle.BORDER_THICK);
+               cs3.setBorderBottom(BorderStyle.THICK);
                for (int cellnum = 0; cellnum < 50; cellnum++) {
                        HSSFCell c = r.createCell(cellnum);
                        c.setCellStyle(cs3);
@@ -123,8 +124,11 @@ public final class HSSFReadWrite {
 
                // end deleted sheet
                FileOutputStream out = new FileOutputStream(outputFilename);
-               wb.write(out);
-               out.close();
+               try {
+                   wb.write(out);
+               } finally {
+                   out.close();
+               }
                
                wb.close();
        }
index 1230449d71ea711b3a0fcb31da0cedbc40c1ac56..ace1ef3a98447b08f802e99ebb5fe4e376d689dc 100644 (file)
@@ -71,8 +71,6 @@ public class InCellLists {
         HSSFSheet sheet = null;\r
         HSSFRow row = null;\r
         HSSFCell cell = null;\r
-        File outputFile = null;\r
-        FileOutputStream fos = null;\r
         ArrayList<MultiLevelListItem> multiLevelListItems = null;\r
         ArrayList<String> listItems = null;\r
         try {\r
@@ -170,9 +168,12 @@ public class InCellLists {
             row.setHeight((short)2800);\r
 \r
             // Save the completed workbook\r
-            outputFile = new File(outputFilename);\r
-            fos = new FileOutputStream(outputFile);\r
-            workbook.write(fos);\r
+            FileOutputStream fos = new FileOutputStream(new File(outputFilename));\r
+            try {\r
+                workbook.write(fos);\r
+            } finally {\r
+                fos.close();\r
+            }\r
         }\r
         catch(FileNotFoundException fnfEx) {\r
             System.out.println("Caught a: " + fnfEx.getClass().getName());\r
@@ -190,9 +191,6 @@ public class InCellLists {
             if (workbook != null) {\r
                 workbook.close();\r
             }\r
-            if (fos != null) {\r
-                fos.close();\r
-            }\r
         }\r
     }\r
 \r
index eb7532c7b450eda239dec4aebc06da259cff2db7..0403bc79529806b42861984ad36ea99b56880c56 100644 (file)
  */
 package org.apache.poi.ss.examples;
 
-import org.apache.poi.ss.usermodel.*;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.ss.util.CellReference;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.apache.poi.xssf.streaming.SXSSFWorkbook;
-
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.Calendar;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.IndexedColors;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
 public class SSPerformanceTest {
-    public static void main(String[] args) {
+    public static void main(String[] args) throws IOException {
         if (args.length != 4) usage("need four command arguments");
 
         String type = args[0];
@@ -52,6 +58,8 @@ public class SSPerformanceTest {
         }
         long timeFinished = System.currentTimeMillis();
         System.out.println("Elapsed " + (timeFinished-timeStarted)/1000 + " seconds");
+        
+        workBook.close();
     }
 
     private static void addContent(Workbook workBook, boolean isHType, int rows, int cols) {
@@ -147,7 +155,7 @@ public class SSPerformanceTest {
 
         Font headerFont = wb.createFont();
         headerFont.setFontHeightInPoints((short) 14);
-        headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
+        headerFont.setBold(true);
         style = wb.createCellStyle();
         style.setAlignment(CellStyle.ALIGN_CENTER);
         style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
@@ -159,7 +167,7 @@ public class SSPerformanceTest {
         Font monthFont = wb.createFont();
         monthFont.setFontHeightInPoints((short)12);
         monthFont.setColor(IndexedColors.RED.getIndex());
-        monthFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
+        monthFont.setBold(true);
         style = wb.createCellStyle();
         style.setAlignment(CellStyle.ALIGN_CENTER);
         style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
index f6a33bf40543ef5ed5759332864950fdee82a485..c98e58fbe8af8eead64681a7a7c6fb31fb06f553 100644 (file)
@@ -89,7 +89,7 @@ public class OldExcelExtractor implements Closeable {
         }
         
         @SuppressWarnings("resource")
-        FileInputStream biffStream = new FileInputStream(f);
+        FileInputStream biffStream = new FileInputStream(f); // NOSONAR
         try {
             open(biffStream);
         } catch (IOException e)  {
index b78a81f851230af7c7de7c266f0918dfc6db91b0..0bc179a57153e78ee50c1c6fa19e6d7e9d316127 100644 (file)
@@ -89,7 +89,7 @@ public final class ColorGradientFormatting implements Cloneable {
         return thresholds;
     }
     public void setThresholds(ColorGradientThreshold[] thresholds) {
-        this.thresholds = thresholds;
+        this.thresholds = (thresholds == null) ? null : thresholds.clone();
         updateThresholdPositions();
     }
 
@@ -97,7 +97,7 @@ public final class ColorGradientFormatting implements Cloneable {
         return colors;
     }
     public void setColors(ExtendedColor[] colors) {
-        this.colors = colors;
+        this.colors = (colors == null) ? null : colors.clone();
     }
     
     public boolean isClampToCurve() {
index 08f8bf11415917450be06c260085d0f3ba1771ec..807d67afd12750de70b10d3ae9d984fa1014590f 100644 (file)
@@ -29,7 +29,7 @@ import org.apache.poi.util.LittleEndian;
  * Font Formatting Block of the Conditional Formatting Rule Record.
  */
 public final class FontFormatting implements Cloneable {
-    private byte[] _rawData;
+    private final byte[] _rawData = new byte[RAW_DATA_SIZE];
 
     private static final int OFFSET_FONT_NAME = 0;
     private static final int OFFSET_FONT_HEIGHT = 64;
@@ -88,14 +88,7 @@ public final class FontFormatting implements Cloneable {
      */
     private static final short FONT_WEIGHT_BOLD         = 0x2bc;
 
-    private FontFormatting(byte[] rawData) {
-        _rawData = rawData;
-    }
-
-    public FontFormatting()
-    {
-        this(new byte[RAW_DATA_SIZE]);
-
+    public FontFormatting() {
         setFontHeight(-1);
         setItalic(false);
         setFontWieghtModified(false);
@@ -122,11 +115,8 @@ public final class FontFormatting implements Cloneable {
     }
 
     /** Creates new FontFormatting */
-    public FontFormatting(RecordInputStream in)
-    {
-        this(new byte[RAW_DATA_SIZE]);
-        for (int i = 0; i < _rawData.length; i++)
-        {
+    public FontFormatting(RecordInputStream in) {
+        for (int i = 0; i < _rawData.length; i++) {
             _rawData[i] = in.readByte();
         }
     }
@@ -542,9 +532,9 @@ public final class FontFormatting implements Cloneable {
     }
 
     @Override
-    public FontFormatting clone()
-    {
-        byte[] rawData = _rawData.clone();
-        return new FontFormatting(rawData);
+    public FontFormatting clone() {
+        FontFormatting other = new FontFormatting();
+        System.arraycopy(_rawData, 0, other._rawData, 0, _rawData.length);
+        return other;
     }
 }
index 4a8f885b204fda928cdac78ff1acca308f79b64a..6c984b278466a749ac80bd2a3b8670d052c4cb97 100644 (file)
@@ -71,7 +71,7 @@ public final class IconMultiStateFormatting implements Cloneable {
         return thresholds;
     }
     public void setThresholds(Threshold[] thresholds) {
-        this.thresholds = thresholds;
+        this.thresholds = (thresholds == null) ? null : thresholds.clone();
     }
     
     public boolean isIconOnly() {
index a78a9c3138ee106794d25dd2cc920d3aaf36be9e..5d101f9039a685ed96053519858d75a8b9ab64fe 100644 (file)
@@ -36,7 +36,7 @@ public final class SeriesListRecord extends StandardRecord {
     private  short[]    field_1_seriesNumbers;
 
     public SeriesListRecord(short[] seriesNumbers) {
-       field_1_seriesNumbers = seriesNumbers;
+       field_1_seriesNumbers = (seriesNumbers == null) ? null : seriesNumbers.clone();
     }
 
     public SeriesListRecord(RecordInputStream in) {
@@ -78,7 +78,7 @@ public final class SeriesListRecord extends StandardRecord {
     }
 
     public Object clone() {
-        return new SeriesListRecord(field_1_seriesNumbers.clone());
+        return new SeriesListRecord(field_1_seriesNumbers);
     }
 
     /**
index 97136da9e59a9ee5f8d366e994d19351debd3368..a4defe8dde6705abbbd63c1e8d130f516088baad 100644 (file)
@@ -107,7 +107,7 @@ public final class ExtendedColor implements Cloneable {
         return rgba;
     }
     public void setRGBA(byte[] rgba) {
-        this.rgba = rgba;
+        this.rgba = (rgba == null) ? null : rgba.clone();
     }
     
     /**
index 289428043a2ebba3ff4f5d15021c50cac821baf8..e75f297b036c100a6a8faa8e73590885997c1f59 100644 (file)
@@ -48,7 +48,7 @@ public class Biff8RC4Key extends Biff8EncryptionKey {
         }\r
 \r
         CipherAlgorithm ca = CipherAlgorithm.rc4;\r
-        _secretKey = new SecretKeySpec(keyDigest, ca.jceId);\r
+        _secretKey = new SecretKeySpec(keyDigest.clone(), ca.jceId);\r
     }\r
 \r
     /**\r
index ce8cbf1b127764478aa4c9534193b97d9551a4f2..bf0ca4c4790f13ec6223117fd4888200b82d28ee 100644 (file)
@@ -37,14 +37,14 @@ import org.apache.poi.util.LocaleUtil;
  * Data Validation Constraint
  */
 public class DVConstraint implements DataValidationConstraint {
-       /* package */ public static final class FormulaPair {
+       /* package */ static final class FormulaPair {
 
                private final Ptg[] _formula1;
                private final Ptg[] _formula2;
 
-               public FormulaPair(Ptg[] formula1, Ptg[] formula2) {
-                       _formula1 = formula1;
-                       _formula2 = formula2;
+               FormulaPair(Ptg[] formula1, Ptg[] formula2) {
+                       _formula1 = (formula1 == null) ? null : formula1.clone();
+                       _formula2 = (formula2 == null) ? null : formula2.clone();
                }
                public Ptg[] getFormula1() {
                        return _formula1;
@@ -73,7 +73,7 @@ public class DVConstraint implements DataValidationConstraint {
                _formula2 = formulaB;
                _value1 = value1;
                _value2 = value2;
-               _explicitListValues = excplicitListValues;
+               _explicitListValues = (excplicitListValues == null) ? null : excplicitListValues.clone();
        }
        
        
index 3852a83e939d81903bbf16a92b0fe74ee7f0b6ce..1ed09aa683e7057c0fc76d98ec8e84c33d20873b 100644 (file)
@@ -89,7 +89,7 @@ public class FFData
         fillFields( std, offset );\r
     }\r
 \r
-    public void fillFields( final byte[] std, final int startOffset )\r
+    public void fillFields( final byte[] std, final int startOffset ) // NOSONAR\r
     {\r
         int offset = startOffset;\r
 \r