]> source.dussan.org Git - poi.git/commitdiff
Sonar fixes
authorAndreas Beeker <kiwiwings@apache.org>
Sun, 27 Sep 2015 22:14:25 +0000 (22:14 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Sun, 27 Sep 2015 22:14:25 +0000 (22:14 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1705587 13f79535-47bb-0310-9956-ffa450edef68

14 files changed:
src/java/org/apache/poi/ddf/EscherBlipRecord.java
src/java/org/apache/poi/ddf/EscherClientDataRecord.java
src/java/org/apache/poi/ddf/EscherComplexProperty.java
src/java/org/apache/poi/ddf/EscherDggRecord.java
src/java/org/apache/poi/ddf/EscherDump.java
src/java/org/apache/poi/ddf/EscherMetafileBlip.java
src/java/org/apache/poi/ddf/EscherPictBlip.java
src/java/org/apache/poi/dev/RecordGenerator.java
src/java/org/apache/poi/sl/usermodel/Insets2D.java
src/java/org/apache/poi/ss/formula/atp/DateParser.java
src/java/org/apache/poi/ss/formula/functions/Odd.java
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
src/scratchpad/src/org/apache/poi/hdf/event/EventBridge.java
src/scratchpad/src/org/apache/poi/hdf/extractor/StyleDescription.java

index 005cf25fcd30119d58f221b97392ef0f2dc24398..82854f8694dd0e52dfdb5e1872dc2994d489953a 100644 (file)
@@ -71,7 +71,7 @@ public class EscherBlipRecord extends EscherRecord { // TODO - instantiable supe
 
     public void setPictureData(byte[] pictureData) {
         if (pictureData == null) {
-            throw new NullPointerException("picture data can't be null");
+            throw new IllegalArgumentException("picture data can't be null");
         }
         field_pictureData = pictureData.clone();
     }
index 8e519c555e5faa05ea4e37057f3f4131e535e4fd..bea83a83cf96a684efbd2f90392da244f4d32391 100644 (file)
@@ -108,8 +108,9 @@ public class EscherClientDataRecord
     /**
      * Any data recording this record.
      */
-    public void setRemainingData( byte[] remainingData )
-    {
-        this.remainingData = remainingData;
+    public void setRemainingData( byte[] remainingData ) {
+        this.remainingData = (remainingData == null)
+            ? new byte[0]
+            : remainingData.clone();
     }
 }
index 2fddc9d6b600d4d2bc31c0fbccf6a4b0a119def2..689002a99926a0652ac325dff98c0a4b100aa645 100644 (file)
@@ -26,8 +26,6 @@ import org.apache.poi.util.LittleEndian;
  * A complex property differs from a simple property in that the data can not fit inside a 32 bit
  * integer.  See the specification for more detailed information regarding exactly what is
  * stored here.
- *
- * @author Glen Stampoultzis
  */
 public class EscherComplexProperty extends EscherProperty {
     // TODO - make private and final
@@ -43,7 +41,10 @@ public class EscherComplexProperty extends EscherProperty {
      */
     public EscherComplexProperty(short id, byte[] complexData) {
         super(id);
-        _complexData = complexData;
+        if (complexData == null) {
+            throw new IllegalArgumentException("complexData can't be null");
+        }
+        _complexData = complexData.clone();
     }
 
     /**
@@ -56,7 +57,10 @@ public class EscherComplexProperty extends EscherProperty {
      */
     public EscherComplexProperty(short propertyNumber, boolean isBlipId, byte[] complexData) {
         super(propertyNumber, true, isBlipId);
-        _complexData = complexData;
+        if (complexData == null) {
+            throw new IllegalArgumentException("complexData can't be null");
+        }
+        _complexData = complexData.clone();
     }
 
     /**
index 7e8d07cb86d148a204941c9e9fefbab58bb474c6..a0d4e0cbbcb70e3a8707f80701307f07d9051c47 100644 (file)
@@ -121,7 +121,7 @@ public final class EscherDggRecord extends EscherRecord {
 
     public String toString() {
 
-        StringBuffer field_5_string = new StringBuffer();
+        StringBuilder field_5_string = new StringBuilder();
         if(field_5_fileIdClusters != null) for (int i = 0; i < field_5_fileIdClusters.length; i++) {
             field_5_string.append("  DrawingGroupId").append(i+1).append(": ");
             field_5_string.append(field_5_fileIdClusters[i].field_1_drawingGroupId);
@@ -204,7 +204,7 @@ public final class EscherDggRecord extends EscherRecord {
     }
 
     public void setFileIdClusters(FileIdCluster[] fileIdClusters) {
-        this.field_5_fileIdClusters = fileIdClusters;
+        this.field_5_fileIdClusters = fileIdClusters.clone();
     }
 
     public void addCluster(int dgId, int numShapedUsed) {
index 4ed9519c97006b8c4f9334bd6a80e8c5014acf33..66d70bb95e129680a7b8a157ca338de711020f0e 100644 (file)
@@ -744,7 +744,7 @@ public final class EscherDump {
         String result = "";
         result += (short) ( n32 >> 16 );
         result += '.';
-        result += (short) ( n32 & (short) 0xFFFF );
+        result += (short) ( n32 & 0xFFFF );
         return result;
     }
 
index f1444b984319ce67551aeb28c1bb5f37fe25402c..bfde1d15921fdb61bc38c9a84dc48a57a3ffd0e8 100644 (file)
@@ -43,11 +43,11 @@ public final class EscherMetafileBlip extends EscherBlipRecord {
 
     private static final int HEADER_SIZE = 8;
 
-    private byte[] field_1_UID;
+    private final byte[] field_1_UID = new byte[16];
     /**
      * The primary UID is only saved to disk if (blip_instance ^ blip_signature == 1)
      */
-    private byte[] field_2_UID;
+    private final byte[] field_2_UID = new byte[16];
     private int field_2_cb;
     private int field_3_rcBounds_x1;
     private int field_3_rcBounds_y1;
@@ -65,11 +65,9 @@ public final class EscherMetafileBlip extends EscherBlipRecord {
     public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
         int bytesAfterHeader = readHeader( data, offset );
         int pos = offset + HEADER_SIZE;
-        field_1_UID = new byte[16];
         System.arraycopy( data, pos, field_1_UID, 0, 16 ); pos += 16;
 
         if((getOptions() ^ getSignature()) == 0x10){
-            field_2_UID = new byte[16];
             System.arraycopy( data, pos, field_2_UID, 0, 16 ); pos += 16;
         }
 
@@ -173,16 +171,21 @@ public final class EscherMetafileBlip extends EscherBlipRecord {
     }
 
     public void setUID(byte[] uid) {
-        field_1_UID = uid;
+        if (uid == null || uid.length != 16) {
+            throw new IllegalArgumentException("uid must be byte[16]");
+        }
+        System.arraycopy(uid, 0, field_1_UID, 0, field_1_UID.length);
     }
 
-    public byte[] getPrimaryUID()
-    {
+    public byte[] getPrimaryUID() {
         return field_2_UID;
     }
 
     public void setPrimaryUID(byte[] primaryUID) {
-        field_2_UID = primaryUID;
+        if (primaryUID == null || primaryUID.length != 16) {
+            throw new IllegalArgumentException("primaryUID must be byte[16]");
+        }
+        System.arraycopy(primaryUID, 0, field_2_UID, 0, field_2_UID.length);
     }
 
     public int getUncompressedSize() {
index c450d4f18c50c688510b31a3ea8bfdc3130663b2..9dee3dca59999ea59095a555ee8e635b511d931e 100644 (file)
@@ -41,7 +41,7 @@ public final class EscherPictBlip extends EscherBlipRecord {
 
     private static final int HEADER_SIZE = 8;
 
-    private byte[] field_1_UID;
+    private final byte[] field_1_UID = new byte[16];
     private int field_2_cb;
     private int field_3_rcBounds_x1;
     private int field_3_rcBounds_y1;
@@ -59,7 +59,6 @@ public final class EscherPictBlip extends EscherBlipRecord {
         int bytesAfterHeader = readHeader(data, offset);
         int pos = offset + HEADER_SIZE;
 
-        field_1_UID = new byte[16];
         System.arraycopy( data, pos, field_1_UID, 0, 16 ); pos += 16;
         field_2_cb = LittleEndian.getInt( data, pos ); pos += 4;
         field_3_rcBounds_x1 = LittleEndian.getInt( data, pos ); pos += 4;
@@ -146,7 +145,10 @@ public final class EscherPictBlip extends EscherBlipRecord {
     }
 
     public void setUID(byte[] uid) {
-        this.field_1_UID = uid;
+        if (uid == null || uid.length != 16) {
+            throw new IllegalArgumentException("uid must be byte[16]");
+        }
+        System.arraycopy(uid, 0, field_1_UID, 0, field_1_UID.length);
     }
 
     public int getUncompressedSize() {
index b442b8e7adf6f380e7d94d96071b5690f8400f24..f841edec42f68ba751626c4238be9b0dad4008b1 100644 (file)
 package org.apache.poi.dev;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.InputStreamReader;
-import java.io.Reader;
 import java.util.Locale;
 import java.util.Properties;
 
@@ -36,7 +33,6 @@ import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
-import org.apache.poi.util.StringUtil;
 import org.apache.poi.util.XMLHelper;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -70,10 +66,13 @@ public class RecordGenerator {
 
     private static void generateRecords(String defintionsDir, String recordStyleDir, String destSrcPathDir, String testSrcPathDir)
              throws Exception {
-        File definitionsFile = new File(defintionsDir);
+        File definitionsFiles[] = new File(defintionsDir).listFiles();
+        if (definitionsFiles == null) {
+            System.err.println(defintionsDir+" is not a directory.");
+            return;
+        }
 
-        for (int i = 0; i < definitionsFile.listFiles().length; i++) {
-            File file = definitionsFile.listFiles()[i];
+        for (File file : definitionsFiles) {
             if (file.isFile() &&
                     (file.getName().endsWith("_record.xml") ||
                     file.getName().endsWith("_type.xml")
@@ -130,8 +129,7 @@ public class RecordGenerator {
     private static void transform(final File in, final File out, final File xslt)
     throws FileNotFoundException, TransformerException
     {
-        final Reader r = new InputStreamReader(new FileInputStream(xslt), StringUtil.UTF8);
-        final StreamSource ss = new StreamSource(r);
+        final StreamSource ss = new StreamSource(xslt);
         final TransformerFactory tf = TransformerFactory.newInstance();
         final Transformer t;
         try
index 04b4d77cf4c35068138237b3e115f546e1e848d9..89f44502be5a7eff119ba6fdb6bb1b68f528c89d 100644 (file)
@@ -17,8 +17,6 @@
 \r
 package org.apache.poi.sl.usermodel;\r
 \r
-import java.awt.Insets;\r
-\r
 /**\r
  * This is a replacement for {@link java.awt.Insets} which works on doubles\r
  * instead of ints\r
@@ -94,8 +92,8 @@ public class Insets2D {
      * @since       JDK1.1\r
      */\r
     public boolean equals(Object obj) {\r
-    if (obj instanceof Insets) {\r
-        Insets insets = (Insets)obj;\r
+    if (obj instanceof Insets2D) {\r
+        Insets2D insets = (Insets2D)obj;\r
         return ((top == insets.top) && (left == insets.left) &&\r
             (bottom == insets.bottom) && (right == insets.right));\r
     }\r
index 4ab15888f28a65aa6c2eb1efa3ede2f6f13479d6..1cb25527b6104c0f14f5da261a46d76c0a9cbb47 100644 (file)
@@ -28,8 +28,6 @@ import org.apache.poi.util.LocaleUtil;
  * Parser for java dates.
  */
 public class DateParser {
-    public DateParser instance = new DateParser();
-
     private DateParser() {
         // enforcing singleton
     }
index e2e93d92f809f720b2dadec108e990cd426b4831..6762fcb5f76f1fc49429141280a66e2e315d8d76 100644 (file)
@@ -28,18 +28,12 @@ public final class Odd extends NumericFunction.OneArg {
                if (d==0) {
                        return 1;
                }
-               if (d>0) {
-                       return calcOdd(d);
-               }
-               return -calcOdd(-d);
+               return (d>0) ? calcOdd(d) : -calcOdd(-d);
        }
 
        private static long calcOdd(double d) {
                double dpm1 = d+1;
                long x = ((long) dpm1) & PARITY_MASK;
-               if (x == dpm1) {
-                       return x-1;
-               }
-               return x + 1;
+               return ( Double.compare(x, dpm1) == 0 ) ? x-1 : x+1;
        }
 }
index da409b2fccb2858f464eace760488fdad411a0e5..8e52c32a97a321f3f0c56057f465d14e262faf8d 100644 (file)
@@ -1168,7 +1168,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
     }
 
     public int getIndentFromLeft() {
-        return getIndentFromLeft();
+        return getIndentationLeft();
     }
 
     public void setIndentFromLeft(int dxaLeft) {
@@ -1176,7 +1176,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
     }
 
     public int getIndentFromRight() {
-        return getIndentFromRight();
+        return getIndentationRight();
     }
 
     public void setIndentFromRight(int dxaRight) {
index c38805c41fcf52c2c5901a3821a0c5602c25a501..6ff414fcdecf39306ebebb5c9323e3410ceadb78 100644 (file)
@@ -81,13 +81,17 @@ public final class EventBridge implements HDFLowLevelParsingListener
   {
     _listener = listener;
   }
-  public void mainDocument(byte[] mainDocument)
-  {
-    _mainDocument = mainDocument;
+  public void mainDocument(byte[] mainDocument) {
+      if (mainDocument == null) {
+          throw new IllegalArgumentException("mainDocument is null.");
+      }
+    _mainDocument = mainDocument.clone();
   }
-  public void tableStream(byte[] tableStream)
-  {
-    _tableStream = tableStream;
+  public void tableStream(byte[] tableStream) {
+      if (tableStream == null) {
+          throw new IllegalArgumentException("tableStream is null.");
+      }
+      _tableStream = tableStream.clone();
   }
   public void miscellaneous(int fcMin, int ccpText, int ccpFtn, int fcPlcfhdd, int lcbPlcfhdd)
   {
index e01590fa53b3005fd90c1822ae134877f37cc41f..cb8588e587d7b1b289072c50276ede5eab453d7a 100644 (file)
@@ -91,7 +91,7 @@ public final class StyleDescription
               System.arraycopy(std, grupxStart + offset + 2, _chpx, 0, upxSize);
           }
 
-          if(upxSize % 2 == 1)
+          if((upxSize & 2) == 1)
           {
               ++upxSize;
           }