You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2016/06/24 22:04:14 UTC

svn commit: r1750171 - in /poi/trunk/src: examples/src/org/apache/poi/hssf/usermodel/examples/ examples/src/org/apache/poi/ss/examples/ java/org/apache/poi/hssf/extractor/ java/org/apache/poi/hssf/record/cf/ java/org/apache/poi/hssf/record/chart/ java/...

Author: kiwiwings
Date: Fri Jun 24 22:04:12 2016
New Revision: 1750171

URL: http://svn.apache.org/viewvc?rev=1750171&view=rev
Log:
Sonar fixes

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

Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java?rev=1750171&r1=1750170&r2=1750171&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java Fri Jun 24 22:04:12 2016
@@ -30,6 +30,7 @@ import org.apache.poi.hssf.usermodel.HSS
 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();
 	}

Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java?rev=1750171&r1=1750170&r2=1750171&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java Fri Jun 24 22:04:12 2016
@@ -71,8 +71,6 @@ public class InCellLists {
         HSSFSheet sheet = null;
         HSSFRow row = null;
         HSSFCell cell = null;
-        File outputFile = null;
-        FileOutputStream fos = null;
         ArrayList<MultiLevelListItem> multiLevelListItems = null;
         ArrayList<String> listItems = null;
         try {
@@ -170,9 +168,12 @@ public class InCellLists {
             row.setHeight((short)2800);
 
             // Save the completed workbook
-            outputFile = new File(outputFilename);
-            fos = new FileOutputStream(outputFile);
-            workbook.write(fos);
+            FileOutputStream fos = new FileOutputStream(new File(outputFilename));
+            try {
+                workbook.write(fos);
+            } finally {
+                fos.close();
+            }
         }
         catch(FileNotFoundException fnfEx) {
             System.out.println("Caught a: " + fnfEx.getClass().getName());
@@ -190,9 +191,6 @@ public class InCellLists {
             if (workbook != null) {
                 workbook.close();
             }
-            if (fos != null) {
-                fos.close();
-            }
         }
     }
 

Modified: poi/trunk/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java?rev=1750171&r1=1750170&r2=1750171&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java Fri Jun 24 22:04:12 2016
@@ -18,21 +18,27 @@
  */
 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);

Modified: poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java?rev=1750171&r1=1750170&r2=1750171&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java Fri Jun 24 22:04:12 2016
@@ -89,7 +89,7 @@ public class OldExcelExtractor implement
         }
         
         @SuppressWarnings("resource")
-        FileInputStream biffStream = new FileInputStream(f);
+        FileInputStream biffStream = new FileInputStream(f); // NOSONAR
         try {
             open(biffStream);
         } catch (IOException e)  {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java?rev=1750171&r1=1750170&r2=1750171&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java Fri Jun 24 22:04:12 2016
@@ -89,7 +89,7 @@ public final class ColorGradientFormatti
         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 ColorGradientFormatti
         return colors;
     }
     public void setColors(ExtendedColor[] colors) {
-        this.colors = colors;
+        this.colors = (colors == null) ? null : colors.clone();
     }
     
     public boolean isClampToCurve() {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java?rev=1750171&r1=1750170&r2=1750171&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java Fri Jun 24 22:04:12 2016
@@ -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 implem
      */
     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 implem
     }
 
     /** 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 implem
     }
 
     @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;
     }
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java?rev=1750171&r1=1750170&r2=1750171&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java Fri Jun 24 22:04:12 2016
@@ -71,7 +71,7 @@ public final class IconMultiStateFormatt
         return thresholds;
     }
     public void setThresholds(Threshold[] thresholds) {
-        this.thresholds = thresholds;
+        this.thresholds = (thresholds == null) ? null : thresholds.clone();
     }
     
     public boolean isIconOnly() {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/chart/SeriesListRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/chart/SeriesListRecord.java?rev=1750171&r1=1750170&r2=1750171&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/chart/SeriesListRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/chart/SeriesListRecord.java Fri Jun 24 22:04:12 2016
@@ -36,7 +36,7 @@ public final class SeriesListRecord exte
     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 exte
     }
 
     public Object clone() {
-        return new SeriesListRecord(field_1_seriesNumbers.clone());
+        return new SeriesListRecord(field_1_seriesNumbers);
     }
 
     /**

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/common/ExtendedColor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/common/ExtendedColor.java?rev=1750171&r1=1750170&r2=1750171&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/common/ExtendedColor.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/common/ExtendedColor.java Fri Jun 24 22:04:12 2016
@@ -107,7 +107,7 @@ public final class ExtendedColor impleme
         return rgba;
     }
     public void setRGBA(byte[] rgba) {
-        this.rgba = rgba;
+        this.rgba = (rgba == null) ? null : rgba.clone();
     }
     
     /**

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/crypto/Biff8RC4Key.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/crypto/Biff8RC4Key.java?rev=1750171&r1=1750170&r2=1750171&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/crypto/Biff8RC4Key.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/crypto/Biff8RC4Key.java Fri Jun 24 22:04:12 2016
@@ -48,7 +48,7 @@ public class Biff8RC4Key extends Biff8En
         }
 
         CipherAlgorithm ca = CipherAlgorithm.rc4;
-        _secretKey = new SecretKeySpec(keyDigest, ca.jceId);
+        _secretKey = new SecretKeySpec(keyDigest.clone(), ca.jceId);
     }
 
     /**

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/DVConstraint.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/DVConstraint.java?rev=1750171&r1=1750170&r2=1750171&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/DVConstraint.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/DVConstraint.java Fri Jun 24 22:04:12 2016
@@ -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 Dat
 		_formula2 = formulaB;
 		_value1 = value1;
 		_value2 = value2;
-		_explicitListValues = excplicitListValues;
+		_explicitListValues = (excplicitListValues == null) ? null : excplicitListValues.clone();
 	}
 	
 	

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FFData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FFData.java?rev=1750171&r1=1750170&r2=1750171&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FFData.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/FFData.java Fri Jun 24 22:04:12 2016
@@ -89,7 +89,7 @@ public class FFData
         fillFields( std, offset );
     }
 
-    public void fillFields( final byte[] std, final int startOffset )
+    public void fillFields( final byte[] std, final int startOffset ) // NOSONAR
     {
         int offset = startOffset;
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org