From: Dominik Stadler Date: Mon, 22 Dec 2014 09:16:16 +0000 (+0000) Subject: Some Eclipse warnings X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a98c9daa0179da8c78cd0f7005095111ea941b71;p=poi.git Some Eclipse warnings git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1647269 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java b/src/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java index d85b6feae5..31b86b1fd9 100644 --- a/src/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java +++ b/src/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java @@ -96,7 +96,7 @@ final class OperationEvaluatorFactory { private static void put(Map m, OperationPtg ptgKey, Function instance) { // make sure ptg has single private constructor because map lookups assume singleton keys - Constructor[] cc = ptgKey.getClass().getDeclaredConstructors(); + Constructor[] cc = ptgKey.getClass().getDeclaredConstructors(); if (cc.length > 1 || !Modifier.isPrivate(cc[0].getModifiers())) { throw new RuntimeException("Failed to verify instance (" + ptgKey.getClass().getName() + ") is a singleton."); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java index 967214380f..4dcaf63bf8 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java @@ -118,38 +118,42 @@ public final class TestXSSFCell extends BaseTestCell { assertEquals(XSSFCell.CELL_TYPE_BLANK, cell_1.getCellType()); } - public void testFormulaString() { + public void testFormulaString() throws IOException { XSSFWorkbook wb = new XSSFWorkbook(); - XSSFCell cell = wb.createSheet().createRow(0).createCell(0); - CTCell ctCell = cell.getCTCell(); //low-level bean holding cell's xml - - cell.setCellFormula("A2"); - assertEquals(XSSFCell.CELL_TYPE_FORMULA, cell.getCellType()); - assertEquals("A2", cell.getCellFormula()); - //the value is not set and cell's type='N' which means blank - assertEquals(STCellType.N, ctCell.getT()); - - //set cached formula value - cell.setCellValue("t='str'"); - //we are still of 'formula' type - assertEquals(XSSFCell.CELL_TYPE_FORMULA, cell.getCellType()); - assertEquals("A2", cell.getCellFormula()); - //cached formula value is set and cell's type='STR' - assertEquals(STCellType.STR, ctCell.getT()); - assertEquals("t='str'", cell.getStringCellValue()); - - //now remove the formula, the cached formula result remains - cell.setCellFormula(null); - assertEquals(XSSFCell.CELL_TYPE_STRING, cell.getCellType()); - assertEquals(STCellType.STR, ctCell.getT()); - //the line below failed prior to fix of Bug #47889 - assertEquals("t='str'", cell.getStringCellValue()); - - //revert to a blank cell - cell.setCellValue((String)null); - assertEquals(XSSFCell.CELL_TYPE_BLANK, cell.getCellType()); - assertEquals(STCellType.N, ctCell.getT()); - assertEquals("", cell.getStringCellValue()); + try { + XSSFCell cell = wb.createSheet().createRow(0).createCell(0); + CTCell ctCell = cell.getCTCell(); //low-level bean holding cell's xml + + cell.setCellFormula("A2"); + assertEquals(XSSFCell.CELL_TYPE_FORMULA, cell.getCellType()); + assertEquals("A2", cell.getCellFormula()); + //the value is not set and cell's type='N' which means blank + assertEquals(STCellType.N, ctCell.getT()); + + //set cached formula value + cell.setCellValue("t='str'"); + //we are still of 'formula' type + assertEquals(XSSFCell.CELL_TYPE_FORMULA, cell.getCellType()); + assertEquals("A2", cell.getCellFormula()); + //cached formula value is set and cell's type='STR' + assertEquals(STCellType.STR, ctCell.getT()); + assertEquals("t='str'", cell.getStringCellValue()); + + //now remove the formula, the cached formula result remains + cell.setCellFormula(null); + assertEquals(XSSFCell.CELL_TYPE_STRING, cell.getCellType()); + assertEquals(STCellType.STR, ctCell.getT()); + //the line below failed prior to fix of Bug #47889 + assertEquals("t='str'", cell.getStringCellValue()); + + //revert to a blank cell + cell.setCellValue((String)null); + assertEquals(XSSFCell.CELL_TYPE_BLANK, cell.getCellType()); + assertEquals(STCellType.N, ctCell.getT()); + assertEquals("", cell.getStringCellValue()); + } finally { + wb.close(); + } } /** @@ -183,15 +187,20 @@ public final class TestXSSFCell extends BaseTestCell { /** * Cell with the formula that returns error must return error code(There was * an problem that cell could not return error value form formula cell). + * @throws IOException */ - public void testGetErrorCellValueFromFormulaCell() { + public void testGetErrorCellValueFromFormulaCell() throws IOException { XSSFWorkbook wb = new XSSFWorkbook(); - XSSFSheet sheet = wb.createSheet(); - XSSFRow row = sheet.createRow(0); - XSSFCell cell = row.createCell(0); - cell.setCellFormula("SQRT(-1)"); - wb.getCreationHelper().createFormulaEvaluator().evaluateFormulaCell(cell); - assertEquals(36, cell.getErrorCellValue()); + try { + XSSFSheet sheet = wb.createSheet(); + XSSFRow row = sheet.createRow(0); + XSSFCell cell = row.createCell(0); + cell.setCellFormula("SQRT(-1)"); + wb.getCreationHelper().createFormulaEvaluator().evaluateFormulaCell(cell); + assertEquals(36, cell.getErrorCellValue()); + } finally { + wb.close(); + } } public void testMissingRAttribute() { @@ -214,8 +223,8 @@ public final class TestXSSFCell extends BaseTestCell { assertCellsWithMissingR(row); - wb = (XSSFWorkbook)_testDataProvider.writeOutAndReadBack(wb); - row = wb.getSheetAt(0).getRow(0); + XSSFWorkbook wbNew = (XSSFWorkbook)_testDataProvider.writeOutAndReadBack(wb); + row = wbNew.getSheetAt(0).getRow(0); assertCellsWithMissingR(row); } @@ -335,33 +344,37 @@ public final class TestXSSFCell extends BaseTestCell { public void test56170Reproduce() throws IOException { final Workbook wb = new XSSFWorkbook(); - final Sheet sheet = wb.createSheet(); - Row row = sheet.createRow(0); - - // by creating Cells out of order we trigger the handling in onDocumentWrite() - Cell cell1 = row.createCell(1); - Cell cell2 = row.createCell(0); - - validateRow(row); - - validateRow(row); - - // once again with removing one cell - row.removeCell(cell1); - - validateRow(row); - - // once again with removing one cell - row.removeCell(cell1); - - // now check again - validateRow(row); - - // once again with removing one cell - row.removeCell(cell2); - - // now check again - validateRow(row); + try { + final Sheet sheet = wb.createSheet(); + Row row = sheet.createRow(0); + + // by creating Cells out of order we trigger the handling in onDocumentWrite() + Cell cell1 = row.createCell(1); + Cell cell2 = row.createCell(0); + + validateRow(row); + + validateRow(row); + + // once again with removing one cell + row.removeCell(cell1); + + validateRow(row); + + // once again with removing one cell + row.removeCell(cell1); + + // now check again + validateRow(row); + + // once again with removing one cell + row.removeCell(cell2); + + // now check again + validateRow(row); + } finally { + wb.close(); + } } private void validateRow(Row row) { diff --git a/src/testcases/org/apache/poi/ss/format/TestCellFormat.java b/src/testcases/org/apache/poi/ss/format/TestCellFormat.java index 42adda983b..9d2d7580c3 100644 --- a/src/testcases/org/apache/poi/ss/format/TestCellFormat.java +++ b/src/testcases/org/apache/poi/ss/format/TestCellFormat.java @@ -16,11 +16,14 @@ ==================================================================== */ package org.apache.poi.ss.format; +import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; -import javax.swing.*; +import javax.swing.JLabel; + +import junit.framework.TestCase; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; @@ -29,8 +32,6 @@ import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; -import junit.framework.TestCase; - public class TestCellFormat extends TestCase { private static final String _255_POUND_SIGNS; @@ -825,15 +826,19 @@ public class TestCellFormat extends TestCase { } - public void testSimpleFractionFormat() { + public void testSimpleFractionFormat() throws IOException { CellFormat cf1 = CellFormat.getInstance("# ?/?"); // Create a workbook, row and cell to test with Workbook wb = new HSSFWorkbook(); - Sheet sheet = wb.createSheet(); - Row row = sheet.createRow(0); - Cell cell = row.createCell(0); - cell.setCellValue(123456.6); - System.out.println(cf1.apply(cell).text); - assertEquals("123456 3/5", cf1.apply(cell).text); + try { + Sheet sheet = wb.createSheet(); + Row row = sheet.createRow(0); + Cell cell = row.createCell(0); + cell.setCellValue(123456.6); + System.out.println(cf1.apply(cell).text); + assertEquals("123456 3/5", cf1.apply(cell).text); + } finally { + wb.close(); + } } } \ No newline at end of file