aboutsummaryrefslogtreecommitdiffstats
path: root/poi-ooxml
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-11-14 10:18:40 +0000
committerPJ Fanning <fanningpj@apache.org>2021-11-14 10:18:40 +0000
commit8365ee1611c87346277854f3333d3c5f3668e7b9 (patch)
tree68e624e50f3bed91e6622207708452ae8de96a80 /poi-ooxml
parent20c0ac1637acb8069b656452ff39eb0dbf9baef1 (diff)
downloadpoi-8365ee1611c87346277854f3333d3c5f3668e7b9.tar.gz
poi-8365ee1611c87346277854f3333d3c5f3668e7b9.zip
[github-278] Resolve all SpotBugs P1 issues in Main and Test. Thanks to Andreas Reichel. This closes #278
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895016 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml')
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java7
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java9
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/SheetDataWriterWithDecorator.java7
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFGradientFillProperties.java2
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFLinearShadeProperties.java2
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFPictureFillProperties.java2
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java2
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java2
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFScatterChartData.java2
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFSurface3DChartData.java2
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFSurfaceChartData.java2
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFBodyProperties.java4
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFPasswordHelper.java6
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java6
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/DummyKeystore.java7
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/util/tests/TestIdentifierManager.java6
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTable.java19
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java16
18 files changed, 53 insertions, 50 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java
index 2fb1749d4b..f66808354a 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java
@@ -24,7 +24,6 @@ import java.io.FileOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.security.SecureRandom;
import java.util.Enumeration;
import javax.crypto.Cipher;
@@ -44,6 +43,7 @@ import org.apache.poi.poifs.crypt.CipherAlgorithm;
import org.apache.poi.poifs.crypt.CryptoFunctions;
import org.apache.poi.util.Beta;
import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.RandomSingleton;
import org.apache.poi.util.TempFile;
/**
@@ -106,10 +106,9 @@ public final class AesZipFileZipEntrySource implements ZipEntrySource {
public static AesZipFileZipEntrySource createZipEntrySource(InputStream is) throws IOException {
// generate session key
- SecureRandom sr = new SecureRandom();
byte[] ivBytes = new byte[16], keyBytes = new byte[16];
- sr.nextBytes(ivBytes);
- sr.nextBytes(keyBytes);
+ RandomSingleton.getInstance().nextBytes(ivBytes);
+ RandomSingleton.getInstance().nextBytes(keyBytes);
final File tmpFile = TempFile.createTempFile("protectedXlsx", ".zip");
copyToFile(is, tmpFile, keyBytes, ivBytes);
IOUtils.closeQuietly(is);
diff --git a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java
index d0fe43a9c8..bfc35c52d6 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java
@@ -25,7 +25,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
@@ -39,6 +38,7 @@ import org.apache.poi.poifs.crypt.ChainingMode;
import org.apache.poi.poifs.crypt.CipherAlgorithm;
import org.apache.poi.poifs.crypt.CryptoFunctions;
import org.apache.poi.util.Beta;
+import org.apache.poi.util.RandomSingleton;
import org.apache.poi.util.TempFile;
/**
@@ -46,8 +46,8 @@ import org.apache.poi.util.TempFile;
*/
@Beta
public class EncryptedTempData {
- private static Logger LOG = LogManager.getLogger(EncryptedTempData.class);
+ private static final Logger LOG = LogManager.getLogger(EncryptedTempData.class);
private static final CipherAlgorithm cipherAlgorithm = CipherAlgorithm.aes128;
private static final String PADDING = "PKCS5Padding";
private final SecretKeySpec skeySpec;
@@ -56,11 +56,10 @@ public class EncryptedTempData {
private CountingOutputStream outputStream;
public EncryptedTempData() throws IOException {
- SecureRandom sr = new SecureRandom();
ivBytes = new byte[16];
byte[] keyBytes = new byte[16];
- sr.nextBytes(ivBytes);
- sr.nextBytes(keyBytes);
+ RandomSingleton.getInstance().nextBytes(ivBytes);
+ RandomSingleton.getInstance().nextBytes(keyBytes);
skeySpec = new SecretKeySpec(keyBytes, cipherAlgorithm.jceId);
tempFile = TempFile.createTempFile("poi-temp-data", ".tmp");
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/SheetDataWriterWithDecorator.java b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/SheetDataWriterWithDecorator.java
index ea6a0519aa..a034b501fa 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/SheetDataWriterWithDecorator.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/SheetDataWriterWithDecorator.java
@@ -24,7 +24,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
@@ -35,6 +34,7 @@ import org.apache.poi.poifs.crypt.ChainingMode;
import org.apache.poi.poifs.crypt.CipherAlgorithm;
import org.apache.poi.poifs.crypt.CryptoFunctions;
import org.apache.poi.util.Beta;
+import org.apache.poi.util.RandomSingleton;
import org.apache.poi.xssf.streaming.SheetDataWriter;
@Beta
@@ -49,11 +49,10 @@ public class SheetDataWriterWithDecorator extends SheetDataWriter {
void init() {
if(skeySpec == null) {
- SecureRandom sr = new SecureRandom();
ivBytes = new byte[16];
byte[] keyBytes = new byte[16];
- sr.nextBytes(ivBytes);
- sr.nextBytes(keyBytes);
+ RandomSingleton.getInstance().nextBytes(ivBytes);
+ RandomSingleton.getInstance().nextBytes(keyBytes);
skeySpec = new SecretKeySpec(keyBytes, cipherAlgorithm.jceId);
}
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFGradientFillProperties.java b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFGradientFillProperties.java
index ab05448eec..db53d585dc 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFGradientFillProperties.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFGradientFillProperties.java
@@ -46,7 +46,7 @@ public class XDDFGradientFillProperties implements XDDFFillProperties {
if (props.isSetRotWithShape()) {
return props.getRotWithShape();
} else {
- return null;
+ return false;
}
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFLinearShadeProperties.java b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFLinearShadeProperties.java
index 0c3e54a245..73f4205e76 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFLinearShadeProperties.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFLinearShadeProperties.java
@@ -59,7 +59,7 @@ public class XDDFLinearShadeProperties {
if (props.isSetScaled()) {
return props.getScaled();
} else {
- return null;
+ return false;
}
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFPictureFillProperties.java b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFPictureFillProperties.java
index 2999d51e26..02e77f1453 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFPictureFillProperties.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFPictureFillProperties.java
@@ -58,7 +58,7 @@ public class XDDFPictureFillProperties implements XDDFFillProperties {
if (props.isSetRotWithShape()) {
return props.getRotWithShape();
} else {
- return null;
+ return false;
}
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java
index 2f2e6fa738..5313e8825d 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFLine3DChartData.java
@@ -191,7 +191,7 @@ public class XDDFLine3DChartData extends XDDFChartData {
if (series.isSetSmooth()) {
return series.getSmooth().getVal();
} else {
- return null;
+ return false;
}
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java
index 34bad10619..0a94cf96e9 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFLineChartData.java
@@ -174,7 +174,7 @@ public class XDDFLineChartData extends XDDFChartData {
if (series.isSetSmooth()) {
return series.getSmooth().getVal();
} else {
- return null;
+ return false;
}
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFScatterChartData.java b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFScatterChartData.java
index bb500cd20f..ba9864bf00 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFScatterChartData.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFScatterChartData.java
@@ -144,7 +144,7 @@ public class XDDFScatterChartData extends XDDFChartData {
if (series.isSetSmooth()) {
return series.getSmooth().getVal();
} else {
- return null;
+ return false;
}
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFSurface3DChartData.java b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFSurface3DChartData.java
index 982a104632..b61764f168 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFSurface3DChartData.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFSurface3DChartData.java
@@ -82,7 +82,7 @@ public class XDDFSurface3DChartData extends XDDFChartData {
if (chart.isSetWireframe()) {
return chart.getWireframe().getVal();
} else {
- return null;
+ return false;
}
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFSurfaceChartData.java b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFSurfaceChartData.java
index 25e8fad31c..0547a19362 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFSurfaceChartData.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFSurfaceChartData.java
@@ -82,7 +82,7 @@ public class XDDFSurfaceChartData extends XDDFChartData {
if (chart.isSetWireframe()) {
return chart.getWireframe().getVal();
} else {
- return null;
+ return false;
}
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFBodyProperties.java b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFBodyProperties.java
index 80d6f019bf..de7de30ef8 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFBodyProperties.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFBodyProperties.java
@@ -60,7 +60,7 @@ public class XDDFBodyProperties {
if (props.isSetAnchorCtr()) {
return props.getAnchorCtr();
} else {
- return null;
+ return false;
}
}
@@ -216,7 +216,7 @@ public class XDDFBodyProperties {
if (props.isSetRtlCol()) {
return props.getRtlCol();
} else {
- return null;
+ return false;
}
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFPasswordHelper.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFPasswordHelper.java
index 167cee14ff..2933bc8c44 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFPasswordHelper.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFPasswordHelper.java
@@ -19,7 +19,6 @@
package org.apache.poi.xssf.usermodel.helpers;
-import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Base64;
import java.util.Locale;
@@ -28,7 +27,9 @@ import javax.xml.namespace.QName;
import org.apache.poi.poifs.crypt.CryptoFunctions;
import org.apache.poi.poifs.crypt.HashAlgorithm;
+import org.apache.poi.poifs.crypt.temp.EncryptedTempData;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.RandomSingleton;
import org.apache.poi.util.StringUtil;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
@@ -65,8 +66,7 @@ public final class XSSFPasswordHelper {
cur.insertAttributeWithValue(getAttrName(prefix, "password"),
String.format(Locale.ROOT, "%04X", hash).toUpperCase(Locale.ROOT));
} else {
- SecureRandom random = new SecureRandom();
- byte[] salt = random.generateSeed(16);
+ byte[] salt = RandomSingleton.getInstance().generateSeed(16);
// Iterations specifies the number of times the hashing function shall be iteratively run (using each
// iteration's result as the input for the next iteration).
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java
index d0ee95fb35..0ed2adbf9d 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java
@@ -22,7 +22,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;
-import java.security.SecureRandom;
import java.util.Arrays;
import javax.xml.namespace.QName;
@@ -33,6 +32,7 @@ import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.poifs.crypt.CryptoFunctions;
import org.apache.poi.poifs.crypt.HashAlgorithm;
+import org.apache.poi.util.RandomSingleton;
import org.apache.xmlbeans.XmlOptions;
import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STAlgClass;
import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STAlgType;
@@ -46,7 +46,6 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STDocProtect;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.SettingsDocument;
public class XWPFSettings extends POIXMLDocumentPart {
-
private CTSettings ctSettings;
/**
@@ -258,8 +257,7 @@ public class XWPFSettings extends POIXMLDocumentPart {
}
- SecureRandom random = new SecureRandom();
- byte[] salt = random.generateSeed(16);
+ byte[] salt = RandomSingleton.getInstance().generateSeed(16);
// Iterations specifies the number of times the hashing function shall be iteratively run (using each
// iteration's result as the input for the next iteration).
diff --git a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/DummyKeystore.java b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/DummyKeystore.java
index b5e17ac0dd..7f19686fe0 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/DummyKeystore.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/DummyKeystore.java
@@ -40,7 +40,6 @@ import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.PrivateKey;
import java.security.PublicKey;
-import java.security.SecureRandom;
import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
@@ -57,6 +56,7 @@ import java.util.stream.Stream;
import org.apache.poi.poifs.crypt.CryptoFunctions;
import org.apache.poi.poifs.storage.RawDataUtil;
import org.apache.poi.util.LocaleUtil;
+import org.apache.poi.util.RandomSingleton;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.ocsp.OCSPObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
@@ -119,7 +119,6 @@ public class DummyKeystore {
}
}
- private static final SecureRandom RANDOM = new SecureRandom();
private static final String DUMMY_ALIAS = "Test";
private static final String DUMMY_PASS = "test";
@@ -187,7 +186,7 @@ public class DummyKeystore {
public KeyCertPair addEntry(String keyAlias, String keyPass, int keySize, int expiryInMonths) throws GeneralSecurityException, IOException, OperatorCreationException {
if (!keystore.isKeyEntry(keyAlias)) {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
- keyPairGenerator.initialize(new RSAKeyGenParameterSpec(keySize, RSAKeyGenParameterSpec.F4), RANDOM);
+ keyPairGenerator.initialize(new RSAKeyGenParameterSpec(keySize, RSAKeyGenParameterSpec.F4), RandomSingleton.getInstance());
KeyPair pair = keyPairGenerator.generateKeyPair();
Date notBefore = new Date();
@@ -262,7 +261,7 @@ public class DummyKeystore {
X509v3CertificateBuilder certificateGenerator = new X509v3CertificateBuilder(
issuerName
- , new BigInteger(128, new SecureRandom())
+ , new BigInteger(128, RandomSingleton.getInstance())
, notBefore
, notAfter
, new X500Name(subjectDn)
diff --git a/poi-ooxml/src/test/java/org/apache/poi/util/tests/TestIdentifierManager.java b/poi-ooxml/src/test/java/org/apache/poi/util/tests/TestIdentifierManager.java
index 71fe575c67..4bbc64ddc5 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/util/tests/TestIdentifierManager.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/util/tests/TestIdentifierManager.java
@@ -75,9 +75,9 @@ class TestIdentifierManager {
@Test
void testReserveNew() {
IdentifierManager manager = new IdentifierManager(10L,12L);
- assertSame(10L,manager.reserveNew());
- assertSame(11L,manager.reserveNew());
- assertSame(12L,manager.reserveNew());
+ assertEquals(10L,manager.reserveNew());
+ assertEquals(11L,manager.reserveNew());
+ assertEquals(12L,manager.reserveNew());
assertThrows(IllegalStateException.class, manager::reserveNew);
}
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTable.java b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTable.java
index c36035244c..88627ad6a1 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTable.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTable.java
@@ -31,11 +31,9 @@ import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
-import java.util.Random;
import org.apache.poi.sl.draw.DrawTableShape;
import org.apache.poi.sl.usermodel.ShapeType;
@@ -44,6 +42,7 @@ import org.apache.poi.sl.usermodel.StrokeStyle;
import org.apache.poi.sl.usermodel.TableCell.BorderEdge;
import org.apache.poi.sl.usermodel.TextParagraph;
import org.apache.poi.sl.usermodel.VerticalAlignment;
+import org.apache.poi.util.RandomSingleton;
import org.apache.poi.util.TempFile;
import org.apache.poi.xslf.XSLFTestDataSamples;
import org.apache.poi.xslf.util.PPTX2PNG;
@@ -143,17 +142,17 @@ class TestXSLFTable {
String[] names = { "car", "rubber duckie", "phone", "gadget" };
String[] desc = { "new", "used", "untouched" };
- Random r = new Random();
+
for (int row=1; row<=rows; row++) {
String[] line = new String[header.length];
line[0] = Integer.toString(row);
- line[1] = Integer.toString(r.nextInt(1000));
- line[2] = names[r.nextInt(names.length)];
- line[3] = "The "+desc[r.nextInt(desc.length)]+" "+line[2]+" in "+(2017+row);
- line[4] = "$"+r.nextInt(50000);
- line[5] = r.nextInt(100)+"%";
- line[6] = "$"+r.nextInt(50000);
+ line[1] = Integer.toString(RandomSingleton.getInstance().nextInt(1000));
+ line[2] = names[RandomSingleton.getInstance().nextInt(names.length)];
+ line[3] = "The "+desc[RandomSingleton.getInstance().nextInt(desc.length)]+" "+line[2]+" in "+(2017+row);
+ line[4] = "$"+RandomSingleton.getInstance().nextInt(50000);
+ line[5] = RandomSingleton.getInstance().nextInt(100)+"%";
+ line[6] = "$"+RandomSingleton.getInstance().nextInt(50000);
System.arraycopy(line, 0, data[row], 0, header.length);
}
@@ -311,7 +310,7 @@ class TestXSLFTable {
tc0.setText("bla bla bla bla");
tab.setColumnWidth(0, 50);
- // usually text height == 88, but font rendering is plattform dependent
+ // usually text height == 88, but font rendering is platform dependent
// so we use something more reliable
assertTrue(tc0.getTextHeight() > 50);
assertEquals(0, tc0.getLineWidth(), 0);
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java
index f4eb9e0990..f158cc61b6 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java
@@ -366,9 +366,19 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
if (i == 0) {
populateWorkbook(wb);
} else {
- System.gc();
- System.gc();
- System.gc();
+ /*
+ Code explicitly invokes garbage collection. Except for specific use in benchmarking,
+ this is very dubious.
+
+ In the past, situations where people have explicitly invoked the garbage collector in
+ routines such as close or finalize methods has led to huge performance black holes.
+ Garbage collection can be expensive. Any situation that forces hundreds or thousands
+ of garbage collections will bring the machine to a crawl.
+ */
+
+ //System.gc();
+ //System.gc();
+ //System.gc();
}
wb.write(outSteam);