From d01334905266f1ffa103736723a32bd418f875ac Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sun, 20 Mar 2022 10:26:05 +0000 Subject: [PATCH] use spaces for indents git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1899082 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/stress/TestAllFiles.java | 10 +- .../xddf/usermodel/chart/XDDFChartData.java | 2 +- .../poi/xssf/usermodel/XSSFDrawing.java | 24 +-- .../usermodel/XSSFEvaluationWorkbook.java | 16 +- .../usermodel/TestXSSFEvaluationWorkbook.java | 94 +++++----- .../org/apache/poi/hslf/record/PPDrawing.java | 6 +- .../poi/hslf/record/SSSlideInfoAtom.java | 28 +-- .../apache/poi/hslf/record/UserEditAtom.java | 6 +- .../usermodel/HSLFSlideShowEncrypted.java | 2 +- .../org/apache/poi/hwpf/HWPFDocument.java | 2 +- .../poi/hwpf/model/OfficeArtContent.java | 28 +-- .../poi/common/usermodel/HyperlinkType.java | 1 + .../poi/extractor/ExtractorFactory.java | 162 +++++++++--------- .../poi/hssf/record/RecordInputStream.java | 6 +- .../apache/poi/hssf/usermodel/HSSFSheet.java | 1 + .../poi/hssf/usermodel/HSSFWorkbook.java | 18 +- .../org/apache/poi/ss/format/CellFormat.java | 2 +- .../poi/ss/formula/EvaluationWorkbook.java | 36 ++-- .../poi/ss/formula/SheetRangeEvaluator.java | 38 ++-- .../poi/ss/formula/SheetRefEvaluator.java | 12 +- .../org/apache/poi/ss/usermodel/CellType.java | 11 +- .../poi/ss/usermodel/WorkbookFactory.java | 10 +- .../poi/ss/usermodel/BaseTestWorkbook.java | 24 +-- 23 files changed, 270 insertions(+), 269 deletions(-) diff --git a/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java b/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java index d487fffe06..8c94027459 100644 --- a/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java +++ b/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java @@ -135,11 +135,11 @@ public class TestAllFiles { final List result = new ArrayList<>(100); for (String file : scanner.getIncludedFiles()) { - // avoid running on files leftover from previous failed runs - // or being created by tests run in parallel - if(file.endsWith("-saved.xls") || file.endsWith("TestHPSFWritingFunctionality.doc")) { - continue; - } + // avoid running on files leftover from previous failed runs + // or being created by tests run in parallel + if(file.endsWith("-saved.xls") || file.endsWith("TestHPSFWritingFunctionality.doc")) { + continue; + } for (FileHandlerKnown handler : sm.getHandler(file)) { ExcInfo info1 = sm.getExcInfo(file, testName, handler); diff --git a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java index 91ce35e964..b5d9d3308b 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/chart/XDDFChartData.java @@ -47,7 +47,7 @@ import org.openxmlformats.schemas.drawingml.x2006.chart.CTUnsignedInt; */ @Beta public abstract class XDDFChartData { - private static final Logger LOGGER = LogManager.getLogger(XDDFChartData.class); + private static final Logger LOGGER = LogManager.getLogger(XDDFChartData.class); protected XDDFChart parent; protected List series; diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java index e93dd7d788..8a559a8473 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java @@ -244,20 +244,20 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing= _uBook.getNumberOfSheets()) { - // this will throw an exception now as the index is out of bounds - _uBook.getSheetAt(sheetIndex); - } + // verify index and let the method in _uBook throw the exception so we report + // it the same way as in other places + if (sheetIndex < 0 || sheetIndex >= _uBook.getNumberOfSheets()) { + // this will throw an exception now as the index is out of bounds + _uBook.getSheetAt(sheetIndex); + } // Performance optimization: build sheet cache for each sheet to avoid re-creating - // the XSSFEvaluationSheet each time a new cell is evaluated + // the XSSFEvaluationSheet each time a new cell is evaluated // EvaluationWorkbooks make not guarantee to synchronize changes made to // the underlying workbook after the EvaluationWorkbook is created. - final XSSFSheet sheet = _uBook.getSheetAt(sheetIndex); + final XSSFSheet sheet = _uBook.getSheetAt(sheetIndex); return _sheetCache.computeIfAbsent(sheet, rows -> new XSSFEvaluationSheet(sheet)); } diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFEvaluationWorkbook.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFEvaluationWorkbook.java index 5021c30b94..b0bdac458a 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFEvaluationWorkbook.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFEvaluationWorkbook.java @@ -29,52 +29,52 @@ import org.junit.jupiter.api.Test; class TestXSSFEvaluationWorkbook { - @Test - void testRefToBlankCellInArrayFormula() { - Workbook wb = new XSSFWorkbook(); - - FormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator(); - verifySheet(wb, formulaEvaluator); - - verifySheet(wb, formulaEvaluator); - - wb.getCreationHelper().createFormulaEvaluator().evaluateAll(); - } - - private void verifySheet(Workbook wb, FormulaEvaluator formulaEvaluator) { - Sheet sheet = wb.createSheet(); - Row row = sheet.createRow(0); - Cell cellA1 = row.createCell(0); - Cell cellB1 = row.createCell(1); - Cell cellC1 = row.createCell(2); - Row row2 = sheet.createRow(1); - Cell cellA2 = row2.createCell(0); - Cell cellB2 = row2.createCell(1); - Cell cellC2 = row2.createCell(2); - Row row3 = sheet.createRow(2); - Cell cellA3 = row3.createCell(0); - Cell cellB3 = row3.createCell(1); - Cell cellC3 = row3.createCell(2); - - cellA1.setCellValue("1"); - // cell B1 intentionally left blank - cellC1.setCellValue("3"); - - cellA2.setCellFormula("A1"); - cellB2.setCellFormula("B1"); - cellC2.setCellFormula("C1"); - - sheet.setArrayFormula("A1:C1", CellRangeAddress.valueOf("A3:C3")); - - formulaEvaluator.evaluateAll(); - - assertEquals("1", cellA2.getStringCellValue()); - assertEquals(0,cellB2.getNumericCellValue(), 0.00001); - assertEquals("3",cellC2.getStringCellValue()); - - assertEquals("1", cellA3.getStringCellValue()); - assertEquals(0,cellB3.getNumericCellValue(), 0.00001); - assertEquals("3",cellC3.getStringCellValue()); - } + @Test + void testRefToBlankCellInArrayFormula() { + Workbook wb = new XSSFWorkbook(); + + FormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator(); + verifySheet(wb, formulaEvaluator); + + verifySheet(wb, formulaEvaluator); + + wb.getCreationHelper().createFormulaEvaluator().evaluateAll(); + } + + private void verifySheet(Workbook wb, FormulaEvaluator formulaEvaluator) { + Sheet sheet = wb.createSheet(); + Row row = sheet.createRow(0); + Cell cellA1 = row.createCell(0); + Cell cellB1 = row.createCell(1); + Cell cellC1 = row.createCell(2); + Row row2 = sheet.createRow(1); + Cell cellA2 = row2.createCell(0); + Cell cellB2 = row2.createCell(1); + Cell cellC2 = row2.createCell(2); + Row row3 = sheet.createRow(2); + Cell cellA3 = row3.createCell(0); + Cell cellB3 = row3.createCell(1); + Cell cellC3 = row3.createCell(2); + + cellA1.setCellValue("1"); + // cell B1 intentionally left blank + cellC1.setCellValue("3"); + + cellA2.setCellFormula("A1"); + cellB2.setCellFormula("B1"); + cellC2.setCellFormula("C1"); + + sheet.setArrayFormula("A1:C1", CellRangeAddress.valueOf("A3:C3")); + + formulaEvaluator.evaluateAll(); + + assertEquals("1", cellA2.getStringCellValue()); + assertEquals(0,cellB2.getNumericCellValue(), 0.00001); + assertEquals("3",cellC2.getStringCellValue()); + + assertEquals("1", cellA3.getStringCellValue()); + assertEquals(0,cellB3.getNumericCellValue(), 0.00001); + assertEquals("3",cellC3.getStringCellValue()); + } } \ No newline at end of file diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PPDrawing.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PPDrawing.java index e5d86ef930..d710f8b994 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PPDrawing.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PPDrawing.java @@ -129,9 +129,9 @@ public final class PPDrawing extends RecordAtom implements Iterable 86399000) { - LOG.atDebug().log("Invalid data for SSSlideInfoAtom - invalid slideTime: "+ _slideTime); - } + if (_slideTime < 0 || _slideTime > 86399000) { + LOG.atDebug().log("Invalid data for SSSlideInfoAtom - invalid slideTime: "+ _slideTime); + } ofs += LittleEndianConsts.INT_SIZE; _soundIdRef = LittleEndian.getInt(source, ofs); ofs += LittleEndianConsts.INT_SIZE; diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/UserEditAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/UserEditAtom.java index 3dbee3c4b6..d2ade4b591 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/UserEditAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/UserEditAtom.java @@ -137,9 +137,9 @@ public final class UserEditAtom extends PositionDependentRecordAtom } if(offset-start != len) { - throw new HSLFException("Having invalid data in UserEditAtom: " - + "len: " + len + ", offset: " + offset + ", start: " + start); - } + throw new HSLFException("Having invalid data in UserEditAtom: " + + "len: " + len + ", offset: " + offset + ", start: " + start); + } } /** diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java index 1dfeda874f..983da60f8e 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java @@ -120,7 +120,7 @@ public class HSLFSlideShowEncrypted implements Closeable { recordMap.put(encOffset, r); } - this.dea = (DocumentEncryptionAtom)r; + this.dea = (DocumentEncryptionAtom)r; String pass = Biff8EncryptionKey.getCurrentUserPassword(); EncryptionInfo ei = getEncryptionInfo(); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFDocument.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFDocument.java index a058881977..d52c149af1 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFDocument.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFDocument.java @@ -214,7 +214,7 @@ public final class HWPFDocument extends HWPFDocumentCore { * @param istream The InputStream that contains the Word document. * @throws IOException If there is an unexpected IOException from the passed * in InputStream. - * @throws org.apache.poi.EmptyFileException If the given stream is empty + * @throws org.apache.poi.EmptyFileException If the given stream is empty * @throws RuntimeException a number of other runtime exceptions can be thrown, especially if there are problems with the * input format */ diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/OfficeArtContent.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/OfficeArtContent.java index 52b89f3212..9266d798c6 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/OfficeArtContent.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/OfficeArtContent.java @@ -38,7 +38,7 @@ import static org.apache.logging.log4j.util.Unbox.box; */ @Internal public final class OfficeArtContent { - protected static final Logger LOG = LogManager.getLogger(OfficeArtContent.class); + protected static final Logger LOG = LogManager.getLogger(OfficeArtContent.class); /** * {@link EscherRecordTypes#DGG_CONTAINER} containing drawing group information for the document. @@ -78,9 +78,9 @@ public final class OfficeArtContent { EscherRecordFactory recordFactory = new DefaultEscherRecordFactory(); int pos = offset; pos += drawingGroupData.fillFields(data, pos, recordFactory); - if (drawingGroupData.getRecordId() == EscherRecordTypes.DGG_CONTAINER.typeID) { - LOG.atDebug().log("Invalid record-id for filling Escher records: " + drawingGroupData.getRecordId()); - } + if (drawingGroupData.getRecordId() == EscherRecordTypes.DGG_CONTAINER.typeID) { + LOG.atDebug().log("Invalid record-id for filling Escher records: " + drawingGroupData.getRecordId()); + } /* * After the drawingGroupData there is an array (2 slots max) that has data about drawings. According to the @@ -98,16 +98,16 @@ public final class OfficeArtContent { byte dgglbl = data[pos]; if (dgglbl != 0x00 && dgglbl != 0x01) { - throw new IllegalArgumentException("Invalid dgglbl when filling Escher records: " + dgglbl); - } + throw new IllegalArgumentException("Invalid dgglbl when filling Escher records: " + dgglbl); + } pos++; EscherContainerRecord dgContainer = new EscherContainerRecord(); pos+= dgContainer.fillFields(data, pos, recordFactory); - if (dgContainer.getRecordId() != EscherRecordTypes.DG_CONTAINER.typeID) { - throw new IllegalArgumentException("Did have an invalid record-type: " + dgContainer.getRecordId() + - " when filling Escher records"); - } + if (dgContainer.getRecordId() != EscherRecordTypes.DG_CONTAINER.typeID) { + throw new IllegalArgumentException("Did have an invalid record-type: " + dgContainer.getRecordId() + + " when filling Escher records"); + } switch (dgglbl) { case 0x00: @@ -122,10 +122,10 @@ public final class OfficeArtContent { } } - if (pos != offset + size) { - throw new IllegalStateException("Did not read all data when filling Escher records: " - + "pos: " + pos + ", offset: " + offset + ", size: " + size); - } + if (pos != offset + size) { + throw new IllegalStateException("Did not read all data when filling Escher records: " + + "pos: " + pos + ", offset: " + offset + ", size: " + size); + } } private List getDgContainers() { diff --git a/poi/src/main/java/org/apache/poi/common/usermodel/HyperlinkType.java b/poi/src/main/java/org/apache/poi/common/usermodel/HyperlinkType.java index 74fa7b6e5f..6152a85e45 100644 --- a/poi/src/main/java/org/apache/poi/common/usermodel/HyperlinkType.java +++ b/poi/src/main/java/org/apache/poi/common/usermodel/HyperlinkType.java @@ -72,6 +72,7 @@ public enum HyperlinkType { * * @return the old integer code for a HyperlinkType enum */ + @Deprecated @Internal(since="3.15 beta 3") int getCode() { return code; diff --git a/poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java b/poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java index 759e75e068..1fad9152eb 100644 --- a/poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java +++ b/poi/src/main/java/org/apache/poi/extractor/ExtractorFactory.java @@ -138,50 +138,50 @@ public final class ExtractorFactory { return (allPreferEventExtractors != null) ? allPreferEventExtractors : threadPreferEventExtractors.get(); } - /** - * Create an extractor that can be used to read text from the given file. - * - * @param fs The file-system which wraps the data of the file. - * @return A POITextExtractor that can be used to fetch text-content of the file. - * @throws IOException If reading the file-data fails - */ + /** + * Create an extractor that can be used to read text from the given file. + * + * @param fs The file-system which wraps the data of the file. + * @return A POITextExtractor that can be used to fetch text-content of the file. + * @throws IOException If reading the file-data fails + */ public static POITextExtractor createExtractor(POIFSFileSystem fs) throws IOException { return createExtractor(fs, getCurrentUserPassword()); } - /** - * Create an extractor that can be used to read text from the given file. - * - * @param fs The file-system which wraps the data of the file. - * @param password The password that is necessary to open the file - * @return A POITextExtractor that can be used to fetch text-content of the file. - * @throws IOException If reading the file-data fails - */ + /** + * Create an extractor that can be used to read text from the given file. + * + * @param fs The file-system which wraps the data of the file. + * @param password The password that is necessary to open the file + * @return A POITextExtractor that can be used to fetch text-content of the file. + * @throws IOException If reading the file-data fails + */ public static POITextExtractor createExtractor(POIFSFileSystem fs, String password) throws IOException { return createExtractor(fs.getRoot(), password); } - /** - * Create an extractor that can be used to read text from the given file. - * - * @param input A stream which wraps the data of the file. - * @return A POITextExtractor that can be used to fetch text-content of the file. - * @throws IOException If reading the file-data fails - * @throws EmptyFileException If the given file is empty - */ + /** + * Create an extractor that can be used to read text from the given file. + * + * @param input A stream which wraps the data of the file. + * @return A POITextExtractor that can be used to fetch text-content of the file. + * @throws IOException If reading the file-data fails + * @throws EmptyFileException If the given file is empty + */ public static POITextExtractor createExtractor(InputStream input) throws IOException { return createExtractor(input, getCurrentUserPassword()); } - /** - * Create an extractor that can be used to read text from the given file. - * - * @param input A stream which wraps the data of the file. - * @param password The password that is necessary to open the file - * @return A POITextExtractor that can be used to fetch text-content of the file. - * @throws IOException If reading the file-data fails - * @throws EmptyFileException If the given file is empty - */ + /** + * Create an extractor that can be used to read text from the given file. + * + * @param input A stream which wraps the data of the file. + * @param password The password that is necessary to open the file + * @return A POITextExtractor that can be used to fetch text-content of the file. + * @throws IOException If reading the file-data fails + * @throws EmptyFileException If the given file is empty + */ public static POITextExtractor createExtractor(InputStream input, String password) throws IOException { final InputStream is = FileMagic.prepareToCheckMagic(input); byte[] emptyFileCheck = new byte[1]; @@ -207,27 +207,27 @@ public final class ExtractorFactory { return wp(isOOXML ? FileMagic.OOXML : fm, w -> w.create(root, password)); } - /** - * Create an extractor that can be used to read text from the given file. - * - * @param file The file to read - * @return A POITextExtractor that can be used to fetch text-content of the file. - * @throws IOException If reading the file-data fails - * @throws EmptyFileException If the given file is empty - */ + /** + * Create an extractor that can be used to read text from the given file. + * + * @param file The file to read + * @return A POITextExtractor that can be used to fetch text-content of the file. + * @throws IOException If reading the file-data fails + * @throws EmptyFileException If the given file is empty + */ public static POITextExtractor createExtractor(File file) throws IOException { return createExtractor(file, getCurrentUserPassword()); } - /** - * Create an extractor that can be used to read text from the given file. - * - * @param file The file to read - * @param password The password that is necessary to open the file - * @return A POITextExtractor that can be used to fetch text-content of the file. - * @throws IOException If reading the file-data fails - * @throws EmptyFileException If the given file is empty - */ + /** + * Create an extractor that can be used to read text from the given file. + * + * @param file The file to read + * @param password The password that is necessary to open the file + * @return A POITextExtractor that can be used to fetch text-content of the file. + * @throws IOException If reading the file-data fails + * @throws EmptyFileException If the given file is empty + */ @SuppressWarnings({"java:S2095"}) public static POITextExtractor createExtractor(File file, String password) throws IOException { if (file.length() == 0) { @@ -275,22 +275,22 @@ public final class ExtractorFactory { return createExtractor(root, getCurrentUserPassword()); } - /** - * Create the Extractor, if possible. Generally needs the Scratchpad jar. - * Note that this won't check for embedded OOXML resources either, use - * {@link org.apache.poi.ooxml.extractor.POIXMLExtractorFactory} for that. - * - * @param root The {@link DirectoryNode} pointing to a document. - * @param password The password that is necessary to open the file - * - * @return The resulting {@link POITextExtractor}, an exception is thrown if - * no TextExtractor can be created for some reason. - * - * @throws IOException If converting the {@link DirectoryNode} into a HSSFWorkbook fails - * @throws org.apache.poi.OldFileFormatException If the {@link DirectoryNode} points to a format of - * an unsupported version of Excel. - * @throws IllegalArgumentException If creating the Extractor fails - */ + /** + * Create the Extractor, if possible. Generally needs the Scratchpad jar. + * Note that this won't check for embedded OOXML resources either, use + * {@link org.apache.poi.ooxml.extractor.POIXMLExtractorFactory} for that. + * + * @param root The {@link DirectoryNode} pointing to a document. + * @param password The password that is necessary to open the file + * + * @return The resulting {@link POITextExtractor}, an exception is thrown if + * no TextExtractor can be created for some reason. + * + * @throws IOException If converting the {@link DirectoryNode} into a HSSFWorkbook fails + * @throws org.apache.poi.OldFileFormatException If the {@link DirectoryNode} points to a format of + * an unsupported version of Excel. + * @throws IllegalArgumentException If creating the Extractor fails + */ public static POITextExtractor createExtractor(final DirectoryNode root, String password) throws IOException { // Encrypted OOXML files go inside OLE2 containers, is this one? if (root.hasEntry(DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE)) { @@ -300,22 +300,22 @@ public final class ExtractorFactory { } } - /** - * Returns an array of text extractors, one for each of - * the embedded documents in the file (if there are any). - * If there are no embedded documents, you'll get back an - * empty array. Otherwise, you'll get one open - * {@link POITextExtractor} for each embedded file. - * - * @param ext The extractor to look at for embedded documents - * - * @return An array of resulting extractors. Empty if no embedded documents are found. - * - * @throws IOException If converting the {@link DirectoryNode} into a HSSFWorkbook fails - * @throws org.apache.poi.OldFileFormatException If the {@link DirectoryNode} points to a format of - * an unsupported version of Excel. - * @throws IllegalArgumentException If creating the Extractor fails - */ + /** + * Returns an array of text extractors, one for each of + * the embedded documents in the file (if there are any). + * If there are no embedded documents, you'll get back an + * empty array. Otherwise, you'll get one open + * {@link POITextExtractor} for each embedded file. + * + * @param ext The extractor to look at for embedded documents + * + * @return An array of resulting extractors. Empty if no embedded documents are found. + * + * @throws IOException If converting the {@link DirectoryNode} into a HSSFWorkbook fails + * @throws org.apache.poi.OldFileFormatException If the {@link DirectoryNode} points to a format of + * an unsupported version of Excel. + * @throws IllegalArgumentException If creating the Extractor fails + */ public static POITextExtractor[] getEmbeddedDocsTextExtractors(POIOLE2TextExtractor ext) throws IOException { if (ext == null) { throw new IllegalStateException("extractor must be given"); diff --git a/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java b/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java index 1ff551c332..2084e6eb6b 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java @@ -420,9 +420,9 @@ public final class RecordInputStream implements LittleEndianInput { nextRecord(); // note - the compressed flag may change on the fly byte compressFlag = readByte(); - if (compressFlag != 0 && compressFlag != 1) { - throw new RecordFormatException("Invalid compressFlag: " + compressFlag); - } + if (compressFlag != 0 && compressFlag != 1) { + throw new RecordFormatException("Invalid compressFlag: " + compressFlag); + } isCompressedEncoding = (compressFlag == 0); } } diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index a0984ae0d9..442cd39a63 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -1490,6 +1490,7 @@ public final class HSSFSheet implements Sheet { * @param isRow unused, kept for backwards compatibility * @deprecated POI 3.15 beta 2. Use {@link HSSFRowShifter#shiftMergedRegions(int, int, int)}. */ + @Deprecated protected void shiftMerged(int startRow, int endRow, int n, boolean isRow) { RowShifter rowShifter = new HSSFRowShifter(this); rowShifter.shiftMergedRegions(startRow, endRow, n); diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index 10d3d4964b..82877661d7 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -935,22 +935,22 @@ public final class HSSFWorkbook extends POIDocument implements Workbook { throw new IllegalArgumentException("sheetName must not be null"); } - if (workbook.doesContainsSheetName(sheetname, _sheets.size())) { - throw new IllegalArgumentException("The workbook already contains a sheet named '" + sheetname + "'"); - } + if (workbook.doesContainsSheetName(sheetname, _sheets.size())) { + throw new IllegalArgumentException("The workbook already contains a sheet named '" + sheetname + "'"); + } - // YK: Mimic Excel and silently truncate sheet names longer than 31 characters + // YK: Mimic Excel and silently truncate sheet names longer than 31 characters // Issue a WARNING though in order to prevent a situation, where the provided long sheet name is // not accessible due to the trimming while we are not even aware of the reason and continue to use // the long name in generated formulas if(sheetname.length() > MAX_SENSITIVE_SHEET_NAME_LEN) { String trimmedSheetname = sheetname.substring(0, MAX_SENSITIVE_SHEET_NAME_LEN); - // we still need to warn about the trimming as the original sheet name won't be available - // e.g. when referenced by formulas - LOGGER.atWarn().log("Sheet '{}' will be added with a trimmed name '{}' for MS Excel compliance.", - sheetname, trimmedSheetname); - sheetname = trimmedSheetname; + // we still need to warn about the trimming as the original sheet name won't be available + // e.g. when referenced by formulas + LOGGER.atWarn().log("Sheet '{}' will be added with a trimmed name '{}' for MS Excel compliance.", + sheetname, trimmedSheetname); + sheetname = trimmedSheetname; } HSSFSheet sheet = new HSSFSheet(this); diff --git a/poi/src/main/java/org/apache/poi/ss/format/CellFormat.java b/poi/src/main/java/org/apache/poi/ss/format/CellFormat.java index 174ccf67b7..bf0bc110ca 100644 --- a/poi/src/main/java/org/apache/poi/ss/format/CellFormat.java +++ b/poi/src/main/java/org/apache/poi/ss/format/CellFormat.java @@ -94,7 +94,7 @@ import org.apache.poi.util.LocaleUtil; */ public class CellFormat { /** The logger to use in the formatting code. */ - private static final Logger LOG = LogManager.getLogger(CellFormat.class); + private static final Logger LOG = LogManager.getLogger(CellFormat.class); private static final Pattern ONE_PART = Pattern.compile( CellFormatPart.FORMAT_PAT.pattern() + "(;|$)", diff --git a/poi/src/main/java/org/apache/poi/ss/formula/EvaluationWorkbook.java b/poi/src/main/java/org/apache/poi/ss/formula/EvaluationWorkbook.java index 90600ec5a3..026df65c0f 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/EvaluationWorkbook.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/EvaluationWorkbook.java @@ -30,13 +30,13 @@ import org.apache.poi.util.Internal; @Internal public interface EvaluationWorkbook { - /** - * Returns the name of the sheet at the given 0-based index. - * - * @param sheetIndex The 0-based index of the sheet - * @return The name of the sheet - * @throws IllegalArgumentException If the index is outside the indices of available sheets - */ + /** + * Returns the name of the sheet at the given 0-based index. + * + * @param sheetIndex The 0-based index of the sheet + * @return The name of the sheet + * @throws IllegalArgumentException If the index is outside the indices of available sheets + */ String getSheetName(int sheetIndex); /** @@ -50,28 +50,28 @@ public interface EvaluationWorkbook { */ int getSheetIndex(String sheetName); - /** - * Get the sheet identified by the given 0-based index. - * - * @param sheetIndex The 0-based index of the sheet - * @return The sheet - * @throws IllegalArgumentException If the index is outside the indices of available sheets - */ + /** + * Get the sheet identified by the given 0-based index. + * + * @param sheetIndex The 0-based index of the sheet + * @return The sheet + * @throws IllegalArgumentException If the index is outside the indices of available sheets + */ EvaluationSheet getSheet(int sheetIndex); /** * HSSF Only - fetch the external-style sheet details *

Return will have no workbook set if it's actually in our own workbook

- * @return The found sheet or null if not found - * @throws IllegalStateException If called with XSSF or SXSSF workbooks + * @return The found sheet or null if not found + * @throws IllegalStateException If called with XSSF or SXSSF workbooks */ ExternalSheet getExternalSheet(int externSheetIndex); /** * XSSF Only - fetch the external-style sheet details *

Return will have no workbook set if it's actually in our own workbook

- * @return The found sheet - * @throws IllegalStateException If called with HSSF workbooks + * @return The found sheet + * @throws IllegalStateException If called with HSSF workbooks */ ExternalSheet getExternalSheet(String firstSheetName, String lastSheetName, int externalWorkbookNumber); /** diff --git a/poi/src/main/java/org/apache/poi/ss/formula/SheetRangeEvaluator.java b/poi/src/main/java/org/apache/poi/ss/formula/SheetRangeEvaluator.java index 3afe4a4851..6d1a1baaa2 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/SheetRangeEvaluator.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/SheetRangeEvaluator.java @@ -74,25 +74,25 @@ final class SheetRangeEvaluator implements SheetRange { return getSheetEvaluator(sheetIndex).getEvalForCell(rowIndex, columnIndex); } - /** - * This method returns a lower row-number if it would lie outside the row-boundaries of - * any sheet. - * - * This is used to optimize cases where very high number of rows would be checked otherwise - * without any benefit as no such row exists anyway. - * - * @param rowIndex The 0-based row-index to check - * @return If the given index lies withing the max row number across all sheets, it is returned. - * Otherwise, the highest used row number across all sheets is returned. - */ - public int adjustRowNumber(int rowIndex) { - int maxRowNum = rowIndex; + /** + * This method returns a lower row-number if it would lie outside the row-boundaries of + * any sheet. + * + * This is used to optimize cases where very high number of rows would be checked otherwise + * without any benefit as no such row exists anyway. + * + * @param rowIndex The 0-based row-index to check + * @return If the given index lies withing the max row number across all sheets, it is returned. + * Otherwise, the highest used row number across all sheets is returned. + */ + public int adjustRowNumber(int rowIndex) { + int maxRowNum = rowIndex; - for (int i = _firstSheetIndex; i < _lastSheetIndex; i++) { - maxRowNum = Math.max(maxRowNum, _sheetEvaluators[i].getLastRowNum()); - } + for (int i = _firstSheetIndex; i < _lastSheetIndex; i++) { + maxRowNum = Math.max(maxRowNum, _sheetEvaluators[i].getLastRowNum()); + } - // do not try to evaluate further than there are rows in any sheet - return Math.min(rowIndex, maxRowNum); - } + // do not try to evaluate further than there are rows in any sheet + return Math.min(rowIndex, maxRowNum); + } } diff --git a/poi/src/main/java/org/apache/poi/ss/formula/SheetRefEvaluator.java b/poi/src/main/java/org/apache/poi/ss/formula/SheetRefEvaluator.java index e765af3bf8..8960efaa31 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/SheetRefEvaluator.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/SheetRefEvaluator.java @@ -90,10 +90,10 @@ final class SheetRefEvaluator { return getSheet().isRowHidden(rowIndex); } - /** - * @return The last used row in this sheet - */ - public int getLastRowNum() { - return getSheet().getLastRowNum(); - } + /** + * @return The last used row in this sheet + */ + public int getLastRowNum() { + return getSheet().getLastRowNum(); + } } diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/CellType.java b/poi/src/main/java/org/apache/poi/ss/usermodel/CellType.java index c8e81c9c1a..510889ec77 100644 --- a/poi/src/main/java/org/apache/poi/ss/usermodel/CellType.java +++ b/poi/src/main/java/org/apache/poi/ss/usermodel/CellType.java @@ -66,20 +66,18 @@ public enum CellType { * @since POI 3.15 beta 3 * @deprecated POI 3.15 beta 3 */ + @Deprecated private final int code; - - /** - * @since POI 3.15 beta 3 - * @deprecated POI 3.15 beta 3 - */ + private CellType(int code) { this.code = code; } - + /** * @since POI 3.15 beta 3. * @deprecated POI 3.15 beta 3. Used to transition code from ints to CellTypes. */ + @Deprecated public static CellType forInt(int code) { for (CellType type : values()) { if (type.code == code) { @@ -93,6 +91,7 @@ public enum CellType { * @since POI 3.15 beta 3 * @deprecated POI 3.15 beta 3 */ + @Deprecated public int getCode() { return code; } diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/WorkbookFactory.java b/poi/src/main/java/org/apache/poi/ss/usermodel/WorkbookFactory.java index 838b82218d..82b9c900d0 100644 --- a/poi/src/main/java/org/apache/poi/ss/usermodel/WorkbookFactory.java +++ b/poi/src/main/java/org/apache/poi/ss/usermodel/WorkbookFactory.java @@ -177,7 +177,7 @@ public final class WorkbookFactory { * * @throws IOException if an error occurs while reading the data * @throws EncryptedDocumentException If the Workbook given is password protected - * @throws EmptyFileException If the given data is empty + * @throws EmptyFileException If the given data is empty * @throws RuntimeException a number of other runtime exceptions can be thrown, especially if there are problems with the * input format */ @@ -206,7 +206,7 @@ public final class WorkbookFactory { * * @throws IOException if an error occurs while reading the data * @throws EncryptedDocumentException If the wrong password is given for a protected file - * @throws EmptyFileException If the given data is empty + * @throws EmptyFileException If the given data is empty * @throws RuntimeException a number of other runtime exceptions can be thrown, especially if there are problems with the * input format */ @@ -247,7 +247,7 @@ public final class WorkbookFactory { * * @throws IOException if an error occurs while reading the data * @throws EncryptedDocumentException If the Workbook given is password protected - * @throws EmptyFileException If the given data is empty + * @throws EmptyFileException If the given data is empty * @throws RuntimeException a number of other runtime exceptions can be thrown, especially if there are problems with the * input format */ @@ -269,7 +269,7 @@ public final class WorkbookFactory { * * @throws IOException if an error occurs while reading the data * @throws EncryptedDocumentException If the wrong password is given for a protected file - * @throws EmptyFileException If the given data is empty + * @throws EmptyFileException If the given data is empty * @throws RuntimeException a number of other runtime exceptions can be thrown, especially if there are problems with the * input format */ @@ -293,7 +293,7 @@ public final class WorkbookFactory { * * @throws IOException if an error occurs while reading the data * @throws EncryptedDocumentException If the wrong password is given for a protected file - * @throws EmptyFileException If the given data is empty + * @throws EmptyFileException If the given data is empty * @throws RuntimeException a number of other runtime exceptions can be thrown, especially if there are problems with the * input format */ diff --git a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestWorkbook.java b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestWorkbook.java index 1f600cf0f2..349e5427fc 100644 --- a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestWorkbook.java +++ b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestWorkbook.java @@ -916,16 +916,16 @@ public abstract class BaseTestWorkbook { } } - @Test - void testSheetNameTrimming() throws IOException { - try (Workbook workbook = _testDataProvider.createWorkbook()) { - Sheet sheet = workbook.createSheet("MyVeryLongSheetName_9999999999999999"); - assertNotNull(sheet); - assertEquals("MyVeryLongSheetName_99999999999", workbook.getSheetName(0)); - - assertThrows(IllegalArgumentException.class, - () -> workbook.createSheet("MyVeryLongSheetName_9999999999999998") - ); - } - } + @Test + void testSheetNameTrimming() throws IOException { + try (Workbook workbook = _testDataProvider.createWorkbook()) { + Sheet sheet = workbook.createSheet("MyVeryLongSheetName_9999999999999999"); + assertNotNull(sheet); + assertEquals("MyVeryLongSheetName_99999999999", workbook.getSheetName(0)); + + assertThrows(IllegalArgumentException.class, + () -> workbook.createSheet("MyVeryLongSheetName_9999999999999998") + ); + } + } } -- 2.39.5