aboutsummaryrefslogtreecommitdiffstats
path: root/poi
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-12-29 13:08:56 +0000
committerPJ Fanning <fanningpj@apache.org>2021-12-29 13:08:56 +0000
commit6784dd81c2abc907e98e49450f39e9475ffb09b0 (patch)
tree9a8ca4114fe58f09cd8a4e91beecd0d23b67766a /poi
parent79a1e6b1e90c613958f91739f15c5f8512f7ee0b (diff)
downloadpoi-6784dd81c2abc907e98e49450f39e9475ffb09b0.tar.gz
poi-6784dd81c2abc907e98e49450f39e9475ffb09b0.zip
update some code based on sonar issues
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896504 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi')
-rw-r--r--poi/src/main/java/org/apache/poi/ss/formula/atp/XMatchFunction.java2
-rw-r--r--poi/src/main/java/org/apache/poi/ss/formula/functions/LookupUtils.java5
-rw-r--r--poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java4
-rw-r--r--poi/src/main/java/org/apache/poi/ss/util/CellUtil.java3
4 files changed, 9 insertions, 5 deletions
diff --git a/poi/src/main/java/org/apache/poi/ss/formula/atp/XMatchFunction.java b/poi/src/main/java/org/apache/poi/ss/formula/atp/XMatchFunction.java
index d627b1287f..f29a393f5f 100644
--- a/poi/src/main/java/org/apache/poi/ss/formula/atp/XMatchFunction.java
+++ b/poi/src/main/java/org/apache/poi/ss/formula/atp/XMatchFunction.java
@@ -94,7 +94,7 @@ final class XMatchFunction implements FreeRefFunction {
vector = LookupUtils.createRowVector(tableArray, 0);
}
int matchedIdx = LookupUtils.xlookupIndexOfValue(lookupValue, vector, matchMode, searchMode);
- return new NumberEval(matchedIdx + 1);
+ return new NumberEval((double)matchedIdx + 1);
} catch (EvaluationException e) {
return e.getErrorEval();
}
diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/LookupUtils.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/LookupUtils.java
index a393e13b65..a74901ab20 100644
--- a/poi/src/main/java/org/apache/poi/ss/formula/functions/LookupUtils.java
+++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/LookupUtils.java
@@ -21,6 +21,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
+import java.util.NoSuchElementException;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.regex.Matcher;
@@ -142,7 +143,9 @@ public final class LookupUtils {
@Override
public Integer next() {
- return pos--;
+ pos--;
+ if (pos < 0) throw new NoSuchElementException();
+ return pos;
}
};
}
diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java
index 1ad1c052fd..1ba040e4da 100644
--- a/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java
+++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java
@@ -177,7 +177,7 @@ public abstract class NumericFunction implements Function {
}
double dpm = Math.abs(d)+1;
long x = ((long) dpm) & PARITY_MASK;
- return MathX.sign(d) * ((Double.compare(x, dpm) == 0) ? x-1 : x+1);
+ return (double) MathX.sign(d) * ((Double.compare(x, dpm) == 0) ? x-1 : x+1);
}
@@ -190,7 +190,7 @@ public abstract class NumericFunction implements Function {
double dpm = Math.abs(d);
long x = ((long) dpm) & PARITY_MASK;
- return MathX.sign(d) * ((Double.compare(x, dpm) == 0) ? x : (x + 2));
+ return (double) MathX.sign(d) * ((Double.compare(x, dpm) == 0) ? x : (x + 2));
}
diff --git a/poi/src/main/java/org/apache/poi/ss/util/CellUtil.java b/poi/src/main/java/org/apache/poi/ss/util/CellUtil.java
index ed468e1b84..76d272c495 100644
--- a/poi/src/main/java/org/apache/poi/ss/util/CellUtil.java
+++ b/poi/src/main/java/org/apache/poi/ss/util/CellUtil.java
@@ -243,7 +243,8 @@ public final class CellUtil {
// Copy CellStyle
if (policy.isCopyCellStyle()) {
- if (destCell.getSheet().getWorkbook() == srcCell.getSheet().getWorkbook()) {
+ if (srcCell.getSheet() != null && destCell.getSheet() != null &&
+ destCell.getSheet().getWorkbook() == srcCell.getSheet().getWorkbook()) {
destCell.setCellStyle(srcCell.getCellStyle());
} else {
CellStyle srcStyle = srcCell.getCellStyle();