From 2e5f0132c56eda57c26231ad59dd16396ebe2293 Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Mon, 16 May 2016 09:57:19 +0000 Subject: [PATCH] Sonar fixes - array is stored directly git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1744003 13f79535-47bb-0310-9956-ffa450edef68 --- .../ss/formula/CollaboratingWorkbooksEnvironment.java | 2 +- src/java/org/apache/poi/ss/formula/Formula.java | 2 +- .../apache/poi/ss/formula/FormulaCellCacheEntry.java | 11 +++++++---- src/java/org/apache/poi/ss/formula/ParseNode.java | 4 +--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/java/org/apache/poi/ss/formula/CollaboratingWorkbooksEnvironment.java b/src/java/org/apache/poi/ss/formula/CollaboratingWorkbooksEnvironment.java index f2d936f3d..58ce3d929 100644 --- a/src/java/org/apache/poi/ss/formula/CollaboratingWorkbooksEnvironment.java +++ b/src/java/org/apache/poi/ss/formula/CollaboratingWorkbooksEnvironment.java @@ -117,7 +117,7 @@ public final class CollaboratingWorkbooksEnvironment { unhookOldEnvironments(evaluators); hookNewEnvironment(evaluators, this); _unhooked = false; - _evaluators = evaluators; + _evaluators = evaluators.clone(); _evaluatorsByName = evaluatorsByName; } diff --git a/src/java/org/apache/poi/ss/formula/Formula.java b/src/java/org/apache/poi/ss/formula/Formula.java index 48c7f391b..9f4f25e90 100644 --- a/src/java/org/apache/poi/ss/formula/Formula.java +++ b/src/java/org/apache/poi/ss/formula/Formula.java @@ -42,7 +42,7 @@ public class Formula { private final int _encodedTokenLen; private Formula(byte[] byteEncoding, int encodedTokenLen) { - _byteEncoding = byteEncoding; + _byteEncoding = byteEncoding.clone(); _encodedTokenLen = encodedTokenLen; // if (false) { // set to true to eagerly check Ptg decoding // LittleEndianByteArrayInputStream in = new LittleEndianByteArrayInputStream(byteEncoding); diff --git a/src/java/org/apache/poi/ss/formula/FormulaCellCacheEntry.java b/src/java/org/apache/poi/ss/formula/FormulaCellCacheEntry.java index 2d399494a..056195618 100644 --- a/src/java/org/apache/poi/ss/formula/FormulaCellCacheEntry.java +++ b/src/java/org/apache/poi/ss/formula/FormulaCellCacheEntry.java @@ -27,8 +27,6 @@ import org.apache.poi.ss.formula.FormulaUsedBlankCellSet.BookSheetKey; /** * Stores the cached result of a formula evaluation, along with the set of sensitive input cells - * - * @author Josh Micich */ final class FormulaCellCacheEntry extends CellCacheEntry { @@ -57,8 +55,13 @@ final class FormulaCellCacheEntry extends CellCacheEntry { public void setSensitiveInputCells(CellCacheEntry[] sensitiveInputCells) { // need to tell all cells that were previously used, but no longer are, // that they are not consumed by this cell any more - changeConsumingCells(sensitiveInputCells == null ? CellCacheEntry.EMPTY_ARRAY : sensitiveInputCells); - _sensitiveInputCells = sensitiveInputCells; + if (sensitiveInputCells == null) { + _sensitiveInputCells = null; + changeConsumingCells(CellCacheEntry.EMPTY_ARRAY); + } else { + _sensitiveInputCells = sensitiveInputCells.clone(); + changeConsumingCells(_sensitiveInputCells); + } } public void clearFormulaEntry() { diff --git a/src/java/org/apache/poi/ss/formula/ParseNode.java b/src/java/org/apache/poi/ss/formula/ParseNode.java index a671ede59..a41ec2634 100644 --- a/src/java/org/apache/poi/ss/formula/ParseNode.java +++ b/src/java/org/apache/poi/ss/formula/ParseNode.java @@ -28,8 +28,6 @@ import org.apache.poi.ss.formula.function.FunctionMetadataRegistry; * Represents a syntactic element from a formula by encapsulating the corresponding Ptg * token. Each ParseNode may have child ParseNodes in the case when the wrapped * Ptg is non-atomic. - * - * @author Josh Micich */ final class ParseNode { @@ -44,7 +42,7 @@ final class ParseNode { throw new IllegalArgumentException("token must not be null"); } _token = token; - _children = children; + _children = children.clone(); _isIf = isIf(token); int tokenCount = 1; for (int i = 0; i < children.length; i++) {