aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/ss/formula
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2020-08-15 00:18:42 +0000
committerAndreas Beeker <kiwiwings@apache.org>2020-08-15 00:18:42 +0000
commit60303201dcb715a7738cd5bff3a85ffb424a2a90 (patch)
tree1154b264901ee5e32e7001175063d64b81f8b73f /src/testcases/org/apache/poi/ss/formula
parente68bd7bd7ded6948a3289c6a6e3ad37453d12c42 (diff)
downloadpoi-60303201dcb715a7738cd5bff3a85ffb424a2a90.tar.gz
poi-60303201dcb715a7738cd5bff3a85ffb424a2a90.zip
use the forbidden-apis policies corresponding to the JRE
fix the forbidden apis issues git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1880866 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/ss/formula')
-rw-r--r--src/testcases/org/apache/poi/ss/formula/constant/TestConstantValueParser.java14
-rw-r--r--src/testcases/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java40
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java2
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestArrayPtg.java2
4 files changed, 25 insertions, 33 deletions
diff --git a/src/testcases/org/apache/poi/ss/formula/constant/TestConstantValueParser.java b/src/testcases/org/apache/poi/ss/formula/constant/TestConstantValueParser.java
index 08ce2d96e4..72a9bcc0d8 100644
--- a/src/testcases/org/apache/poi/ss/formula/constant/TestConstantValueParser.java
+++ b/src/testcases/org/apache/poi/ss/formula/constant/TestConstantValueParser.java
@@ -34,7 +34,7 @@ public final class TestConstantValueParser {
private static final Object[] SAMPLE_VALUES = {
Boolean.TRUE,
null,
- new Double(1.1),
+ 1.1,
"Sample text",
ErrorConstant.valueOf(FormulaError.DIV0.getCode()),
};
@@ -44,29 +44,29 @@ public final class TestConstantValueParser {
"01 9A 99 99 99 99 99 F1 3F " +
"02 0B 00 00 53 61 6D 70 6C 65 20 74 65 78 74 " +
"10 07 00 00 00 00 00 00 00");
-
+
@Test
public void testGetEncodedSize() {
int actual = ConstantValueParser.getEncodedSize(SAMPLE_VALUES);
assertEquals(51, actual);
}
-
+
@Test
public void testEncode() {
int size = ConstantValueParser.getEncodedSize(SAMPLE_VALUES);
byte[] data = new byte[size];
-
+
ConstantValueParser.encode(new LittleEndianByteArrayOutputStream(data, 0), SAMPLE_VALUES);
-
+
if (!Arrays.equals(data, SAMPLE_ENCODING)) {
fail("Encoding differs");
}
}
-
+
@Test
public void testDecode() {
LittleEndianInput in = TestcaseRecordInputStream.createLittleEndian(SAMPLE_ENCODING);
-
+
Object[] values = ConstantValueParser.parse(in, 4);
for (int i = 0; i < values.length; i++) {
if(!isEqual(SAMPLE_VALUES[i], values[i])) {
diff --git a/src/testcases/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java b/src/testcases/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java
index ac2551665d..c408dd527b 100644
--- a/src/testcases/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java
+++ b/src/testcases/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java
@@ -39,19 +39,20 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
-import java.util.zip.ZipException;
import java.util.zip.ZipFile;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
import org.apache.poi.poifs.crypt.CryptoFunctions;
import org.apache.poi.poifs.crypt.HashAlgorithm;
import org.apache.poi.util.TempFile;
+import org.apache.poi.util.XMLHelper;
import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
+import org.xml.sax.helpers.DefaultHandler;
/**
* This class is not used during normal POI run-time but is used at development time to generate
@@ -229,7 +230,7 @@ public final class ExcelFileFormatDocFunctionExtractor {
/**
* To avoid drag-in - parse XML using only JDK.
*/
- private static class EFFDocHandler implements ContentHandler {
+ private static class EFFDocHandler extends DefaultHandler {
private static final String[] HEADING_PATH_NAMES = {
"office:document-content", "office:body", "office:text", "text:h",
};
@@ -339,7 +340,7 @@ public final class ExcelFileFormatDocFunctionExtractor {
processFunction(cellData, noteFlags, 0);
processFunction(cellData, noteFlags, 8);
}
-
+
public void processFunction(String[] cellData, Boolean[] noteFlags, int i) {
String funcIxStr = cellData[i + 0];
if (funcIxStr.length() < 1) {
@@ -428,27 +429,18 @@ public final class ExcelFileFormatDocFunctionExtractor {
}
private static void extractFunctionData(FunctionDataCollector fdc, InputStream is) {
- XMLReader xr;
+ SAXParserFactory sf = XMLHelper.getSaxParserFactory();
+ SAXParser xr;
try {
// First up, try the default one
- xr = XMLReaderFactory.createXMLReader();
- } catch (SAXException e) {
- // Try one for java 1.4
- System.setProperty("org.xml.sax.driver", "org.apache.crimson.parser.XMLReaderImpl");
- try {
- xr = XMLReaderFactory.createXMLReader();
- } catch (SAXException e2) {
- throw new RuntimeException(e2);
- }
+ xr = sf.newSAXParser();
+ } catch (SAXException | ParserConfigurationException e) {
+ throw new RuntimeException(e);
}
- xr.setContentHandler(new EFFDocHandler(fdc));
- InputSource inSrc = new InputSource(is);
-
- try {
- xr.parse(inSrc);
- is.close();
+ try (InputStream is2 = is) {
+ xr.parse(is2, new EFFDocHandler(fdc));
} catch (IOException | SAXException e) {
throw new RuntimeException(e);
}
@@ -463,7 +455,7 @@ public final class ExcelFileFormatDocFunctionExtractor {
public SimpleAsciiOutputStream(OutputStream os) {
_os = os;
}
-
+
@Override
public void write(int b) throws IOException {
checkByte(b);
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java b/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java
index bb8b8e62bb..9c4fdcb2f2 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java
@@ -220,7 +220,7 @@ public class TestStatsLib extends BaseTestNumeric {
}
private static void confirmMode(double[] v, double expectedResult) {
- confirmMode(v, new Double(expectedResult));
+ confirmMode(v, (Double)expectedResult);
}
private static void confirmMode(double[] v, Double expectedResult) {
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestArrayPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestArrayPtg.java
index 960209681b..170c06719b 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestArrayPtg.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestArrayPtg.java
@@ -67,7 +67,7 @@ public final class TestArrayPtg {
assertEquals(Boolean.TRUE, values[0][0]);
assertEquals("ABCD", values[0][1]);
- assertEquals(new Double(0), values[1][0]);
+ assertEquals(0d, values[1][0]);
assertEquals(Boolean.FALSE, values[1][1]);
assertEquals("FG", values[1][2]);