From deffaacd0fbb07a0287c4914a74b47d713ef55dc Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Thu, 25 Aug 2022 18:52:27 +0000 Subject: [PATCH] sonar issues git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903686 13f79535-47bb-0310-9956-ffa450edef68 --- .../ss/formula/SettingExternalFunction.java | 2 -- .../apache/poi/xssf/usermodel/XSSFSheet.java | 4 ++-- .../apache/poi/xslf/TestXSLFSlideCopy.java | 4 ++-- ...tSXSSFWorkbookWithNullAutoSizeTracker.java | 6 ++--- .../charts/TestXSSFBubbleChartData.java | 2 +- .../hemf/record/emfplus/HemfPlusBrush.java | 23 +++++++++++-------- .../org/apache/poi/hsmf/dev/TypesLister.java | 1 - .../poi/poifs/crypt/DataSpaceMapUtils.java | 2 -- .../crypt/binaryrc4/BinaryRC4Encryptor.java | 1 - .../crypt/standard/StandardEncryptor.java | 1 - 10 files changed, 21 insertions(+), 25 deletions(-) diff --git a/poi-examples/src/main/java/org/apache/poi/examples/ss/formula/SettingExternalFunction.java b/poi-examples/src/main/java/org/apache/poi/examples/ss/formula/SettingExternalFunction.java index 308008a4a3..b873db4b2b 100644 --- a/poi-examples/src/main/java/org/apache/poi/examples/ss/formula/SettingExternalFunction.java +++ b/poi-examples/src/main/java/org/apache/poi/examples/ss/formula/SettingExternalFunction.java @@ -25,9 +25,7 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map; -import org.apache.poi.ss.formula.OperationEvaluationContext; import org.apache.poi.ss.formula.eval.ErrorEval; -import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.formula.functions.FreeRefFunction; import org.apache.poi.ss.formula.udf.UDFFinder; import org.apache.poi.ss.usermodel.Row; diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index 3fdd8c1b9a..081adc516a 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -4958,7 +4958,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet, OoxmlSheetEx if (totalsRowCount == 1) { // never seen more than one totals row XSSFRow totalsRow = sheet.getRow(clonedTable.getEndCellReference().getRow()); if (clonedTable.getCTTable().getTableColumns() != null - && clonedTable.getCTTable().getTableColumns().getTableColumnList().size() > 0) { + && !clonedTable.getCTTable().getTableColumns().getTableColumnList().isEmpty()) { clonedTable.getCTTable().setTotalsRowCount(totalsRowCount); for (int i = 0; i < clonedTable.getCTTable().getTableColumns().getTableColumnList().size(); i++) { CTTableColumn tableCol = table.getCTTable().getTableColumns().getTableColumnList().get(i); @@ -4983,7 +4983,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet, OoxmlSheetEx // clone calculated column formulas if (clonedTable.getCTTable().getTableColumns() != null - && clonedTable.getCTTable().getTableColumns().getTableColumnList().size() > 0) { + && !clonedTable.getCTTable().getTableColumns().getTableColumnList().isEmpty()) { clonedTable.getCTTable().setTotalsRowCount(totalsRowCount); for (int i = 0; i < clonedTable.getCTTable().getTableColumns().getTableColumnList().size(); i++) { CTTableColumn tableCol = table.getCTTable().getTableColumns().getTableColumnList().get(i); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideCopy.java b/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideCopy.java index 130238153b..7e198d40b6 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideCopy.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xslf/TestXSLFSlideCopy.java @@ -31,11 +31,11 @@ import java.util.Objects; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; -public class TestXSLFSlideCopy { +class TestXSLFSlideCopy { private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); @Test - public void testCopySlide() throws IOException { + void testCopySlide() throws IOException { final String shapeName = "title"; try ( InputStream stream = slTests.openResourceAsStream("copy-slide-demo.pptx"); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithNullAutoSizeTracker.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithNullAutoSizeTracker.java index e5e9af53d3..1b2352b29d 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithNullAutoSizeTracker.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbookWithNullAutoSizeTracker.java @@ -49,9 +49,9 @@ import static org.apache.poi.POITestCase.assertEndsWith; import static org.apache.poi.POITestCase.assertStartsWith; import static org.junit.jupiter.api.Assertions.*; -public final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook { +final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWorkbook { - public TestSXSSFWorkbookWithNullAutoSizeTracker() { + TestSXSSFWorkbookWithNullAutoSizeTracker() { super(SXSSFITestDataProviderWithNullAutoSizeTracker.instance); } @@ -672,7 +672,7 @@ public final class TestSXSSFWorkbookWithNullAutoSizeTracker extends BaseTestXWor } @Test - public void disableAutoSizeTracker() throws IOException { + void disableAutoSizeTracker() throws IOException { try (Workbook workbook = _testDataProvider.createWorkbook(10)) { assertThrows(IllegalStateException.class, () -> { Sheet sheet = workbook.createSheet("testSheet"); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/charts/TestXSSFBubbleChartData.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/charts/TestXSSFBubbleChartData.java index b8bd3e71b5..6eacb5be89 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/charts/TestXSSFBubbleChartData.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/charts/TestXSSFBubbleChartData.java @@ -39,7 +39,7 @@ import java.util.Calendar; /** * Tests for XSSFBubbleChartData. */ -public final class TestXSSFBubbleChartData { +final class TestXSSFBubbleChartData { @Test void testExample() throws IOException { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java index f2fc063258..69668f3deb 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusBrush.java @@ -355,7 +355,7 @@ public class HemfPlusBrush { size += LittleEndianConsts.INT_SIZE; } - brushBytes = IOUtils.toByteArray(leis, (int)(dataSize-size), MAX_OBJECT_SIZE); + brushBytes = IOUtils.toByteArray(leis, Math.toIntExact(dataSize-size), MAX_OBJECT_SIZE); return dataSize; } @@ -542,7 +542,7 @@ public class HemfPlusBrush { // gradient is repeated. wrapMode = EmfPlusWrapMode.valueOf(leis.readInt()); - int size = 2 * LittleEndianConsts.INT_SIZE; + long size = 2L * LittleEndianConsts.INT_SIZE; size += readRectF(leis, rect); // An EmfPlusARGB object that specifies the color at the starting/ending boundary point of the linear gradient brush. @@ -552,10 +552,11 @@ public class HemfPlusBrush { // skip reserved1/2 fields leis.skipFully(2 * LittleEndianConsts.INT_SIZE); - size += 4 * LittleEndianConsts.INT_SIZE; + size += 4L * LittleEndianConsts.INT_SIZE; if (TRANSFORM.isSet(dataFlags)) { - size += readXForm(leis, (blendTransform = new AffineTransform())); + blendTransform = new AffineTransform(); + size += readXForm(leis, blendTransform); } if (isPreset() && (isBlendH() || isBlendV())) { @@ -709,7 +710,7 @@ public class HemfPlusBrush { // that appears at the center point of the brush. The color of the brush changes gradually from the // boundary color to the center color as it moves from the boundary to the center point. centerColor = readARGB(leis.readInt()); - long size = 3*LittleEndianConsts.INT_SIZE; + long size = 3L * LittleEndianConsts.INT_SIZE; if (wrapMode == null) { return size; @@ -727,7 +728,7 @@ public class HemfPlusBrush { for (int i = 0; i < colorCount; i++) { surroundingColor[i] = readARGB(leis.readInt()); } - size += (colorCount + 1) * LittleEndianConsts.INT_SIZE; + size += (colorCount + 1L) * LittleEndianConsts.INT_SIZE; // The boundary of the path gradient brush, which is specified by either a path or a closed cardinal spline. // If the BrushDataPath flag is set in the BrushDataFlags field, this field MUST contain an @@ -785,7 +786,7 @@ public class HemfPlusBrush { size += 3*LittleEndianConsts.INT_SIZE; } - return Math.toIntExact(size); + return size; } @Override @@ -846,14 +847,16 @@ public class HemfPlusBrush { // across a shape, when the image is smaller than the area being filled. wrapMode = EmfPlusWrapMode.valueOf(leis.readInt()); - long size = 2*LittleEndianConsts.INT_SIZE; + long size = 2L * LittleEndianConsts.INT_SIZE; if (TRANSFORM.isSet(dataFlags)) { - size += readXForm(leis, (brushTransform = new AffineTransform())); + brushTransform = new AffineTransform(); + size += readXForm(leis, brushTransform); } if (dataSize > size) { - size += (image = new EmfPlusImage()).init(leis, dataSize-size, EmfPlusObjectType.IMAGE, 0); + image = new EmfPlusImage(); + size += image.init(leis, dataSize-size, EmfPlusObjectType.IMAGE, 0); } return Math.toIntExact(size); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hsmf/dev/TypesLister.java b/poi-scratchpad/src/main/java/org/apache/poi/hsmf/dev/TypesLister.java index a992bd0cc9..452b8d6ad0 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hsmf/dev/TypesLister.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hsmf/dev/TypesLister.java @@ -19,7 +19,6 @@ package org.apache.poi.hsmf.dev; import java.io.PrintStream; import java.util.ArrayList; -import java.util.Comparator; import org.apache.poi.hsmf.datatypes.MAPIProperty; import org.apache.poi.util.StringUtil; diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java b/poi/src/main/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java index a37aa7ceeb..a904214121 100644 --- a/poi/src/main/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java +++ b/poi/src/main/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java @@ -24,8 +24,6 @@ import org.apache.poi.EncryptedDocumentException; import org.apache.poi.poifs.crypt.standard.EncryptionRecord; import org.apache.poi.poifs.filesystem.DirectoryEntry; import org.apache.poi.poifs.filesystem.DocumentEntry; -import org.apache.poi.poifs.filesystem.POIFSWriterEvent; -import org.apache.poi.poifs.filesystem.POIFSWriterListener; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndianByteArrayOutputStream; import org.apache.poi.util.LittleEndianConsts; diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Encryptor.java b/poi/src/main/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Encryptor.java index 64139ca6b2..c180b6b8e3 100644 --- a/poi/src/main/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Encryptor.java +++ b/poi/src/main/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Encryptor.java @@ -36,7 +36,6 @@ import org.apache.poi.poifs.crypt.Encryptor; import org.apache.poi.poifs.crypt.HashAlgorithm; import org.apache.poi.poifs.crypt.standard.EncryptionRecord; import org.apache.poi.poifs.filesystem.DirectoryNode; -import org.apache.poi.util.LittleEndianByteArrayOutputStream; import org.apache.poi.util.RandomSingleton; public class BinaryRC4Encryptor extends Encryptor { diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java b/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java index 683ac4e807..a5f2559965 100644 --- a/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java +++ b/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java @@ -47,7 +47,6 @@ import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.POIFSWriterEvent; import org.apache.poi.poifs.filesystem.POIFSWriterListener; import org.apache.poi.util.IOUtils; -import org.apache.poi.util.LittleEndianByteArrayOutputStream; import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianOutputStream; import org.apache.poi.util.RandomSingleton; -- 2.39.5