aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2015-09-27 22:14:25 +0000
committerAndreas Beeker <kiwiwings@apache.org>2015-09-27 22:14:25 +0000
commitda47014b1bd398e190e7e949536e1026a7d7b23a (patch)
tree526a936f9ab49fc28a17badae3951906d3775133 /src/java/org
parent28d074b4ebb1c9c5b3f4b0c692ec39b506662bdd (diff)
downloadpoi-da47014b1bd398e190e7e949536e1026a7d7b23a.tar.gz
poi-da47014b1bd398e190e7e949536e1026a7d7b23a.zip
Sonar fixes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1705587 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
-rw-r--r--src/java/org/apache/poi/ddf/EscherBlipRecord.java2
-rw-r--r--src/java/org/apache/poi/ddf/EscherClientDataRecord.java7
-rw-r--r--src/java/org/apache/poi/ddf/EscherComplexProperty.java12
-rw-r--r--src/java/org/apache/poi/ddf/EscherDggRecord.java4
-rw-r--r--src/java/org/apache/poi/ddf/EscherDump.java2
-rw-r--r--src/java/org/apache/poi/ddf/EscherMetafileBlip.java19
-rw-r--r--src/java/org/apache/poi/ddf/EscherPictBlip.java8
-rw-r--r--src/java/org/apache/poi/dev/RecordGenerator.java16
-rw-r--r--src/java/org/apache/poi/sl/usermodel/Insets2D.java6
-rw-r--r--src/java/org/apache/poi/ss/formula/atp/DateParser.java2
-rw-r--r--src/java/org/apache/poi/ss/formula/functions/Odd.java10
11 files changed, 43 insertions, 45 deletions
diff --git a/src/java/org/apache/poi/ddf/EscherBlipRecord.java b/src/java/org/apache/poi/ddf/EscherBlipRecord.java
index 005cf25fcd..82854f8694 100644
--- a/src/java/org/apache/poi/ddf/EscherBlipRecord.java
+++ b/src/java/org/apache/poi/ddf/EscherBlipRecord.java
@@ -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();
}
diff --git a/src/java/org/apache/poi/ddf/EscherClientDataRecord.java b/src/java/org/apache/poi/ddf/EscherClientDataRecord.java
index 8e519c555e..bea83a83cf 100644
--- a/src/java/org/apache/poi/ddf/EscherClientDataRecord.java
+++ b/src/java/org/apache/poi/ddf/EscherClientDataRecord.java
@@ -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();
}
}
diff --git a/src/java/org/apache/poi/ddf/EscherComplexProperty.java b/src/java/org/apache/poi/ddf/EscherComplexProperty.java
index 2fddc9d6b6..689002a999 100644
--- a/src/java/org/apache/poi/ddf/EscherComplexProperty.java
+++ b/src/java/org/apache/poi/ddf/EscherComplexProperty.java
@@ -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();
}
/**
diff --git a/src/java/org/apache/poi/ddf/EscherDggRecord.java b/src/java/org/apache/poi/ddf/EscherDggRecord.java
index 7e8d07cb86..a0d4e0cbbc 100644
--- a/src/java/org/apache/poi/ddf/EscherDggRecord.java
+++ b/src/java/org/apache/poi/ddf/EscherDggRecord.java
@@ -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) {
diff --git a/src/java/org/apache/poi/ddf/EscherDump.java b/src/java/org/apache/poi/ddf/EscherDump.java
index 4ed9519c97..66d70bb95e 100644
--- a/src/java/org/apache/poi/ddf/EscherDump.java
+++ b/src/java/org/apache/poi/ddf/EscherDump.java
@@ -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;
}
diff --git a/src/java/org/apache/poi/ddf/EscherMetafileBlip.java b/src/java/org/apache/poi/ddf/EscherMetafileBlip.java
index f1444b9843..bfde1d1592 100644
--- a/src/java/org/apache/poi/ddf/EscherMetafileBlip.java
+++ b/src/java/org/apache/poi/ddf/EscherMetafileBlip.java
@@ -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() {
diff --git a/src/java/org/apache/poi/ddf/EscherPictBlip.java b/src/java/org/apache/poi/ddf/EscherPictBlip.java
index c450d4f18c..9dee3dca59 100644
--- a/src/java/org/apache/poi/ddf/EscherPictBlip.java
+++ b/src/java/org/apache/poi/ddf/EscherPictBlip.java
@@ -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() {
diff --git a/src/java/org/apache/poi/dev/RecordGenerator.java b/src/java/org/apache/poi/dev/RecordGenerator.java
index b442b8e7ad..f841edec42 100644
--- a/src/java/org/apache/poi/dev/RecordGenerator.java
+++ b/src/java/org/apache/poi/dev/RecordGenerator.java
@@ -19,10 +19,7 @@
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
diff --git a/src/java/org/apache/poi/sl/usermodel/Insets2D.java b/src/java/org/apache/poi/sl/usermodel/Insets2D.java
index 04b4d77cf4..89f44502be 100644
--- a/src/java/org/apache/poi/sl/usermodel/Insets2D.java
+++ b/src/java/org/apache/poi/sl/usermodel/Insets2D.java
@@ -17,8 +17,6 @@
package org.apache.poi.sl.usermodel;
-import java.awt.Insets;
-
/**
* This is a replacement for {@link java.awt.Insets} which works on doubles
* instead of ints
@@ -94,8 +92,8 @@ public class Insets2D {
* @since JDK1.1
*/
public boolean equals(Object obj) {
- if (obj instanceof Insets) {
- Insets insets = (Insets)obj;
+ if (obj instanceof Insets2D) {
+ Insets2D insets = (Insets2D)obj;
return ((top == insets.top) && (left == insets.left) &&
(bottom == insets.bottom) && (right == insets.right));
}
diff --git a/src/java/org/apache/poi/ss/formula/atp/DateParser.java b/src/java/org/apache/poi/ss/formula/atp/DateParser.java
index 4ab15888f2..1cb25527b6 100644
--- a/src/java/org/apache/poi/ss/formula/atp/DateParser.java
+++ b/src/java/org/apache/poi/ss/formula/atp/DateParser.java
@@ -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
}
diff --git a/src/java/org/apache/poi/ss/formula/functions/Odd.java b/src/java/org/apache/poi/ss/formula/functions/Odd.java
index e2e93d92f8..6762fcb5f7 100644
--- a/src/java/org/apache/poi/ss/formula/functions/Odd.java
+++ b/src/java/org/apache/poi/ss/formula/functions/Odd.java
@@ -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;
}
}