]> source.dussan.org Git - poi.git/commitdiff
IDE and JavaDoc fixes, move/remove some unfixed tests
authorDominik Stadler <centic@apache.org>
Fri, 11 Jan 2019 19:31:05 +0000 (19:31 +0000)
committerDominik Stadler <centic@apache.org>
Fri, 11 Jan 2019 19:31:05 +0000 (19:31 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1851089 13f79535-47bb-0310-9956-ffa450edef68

18 files changed:
src/integrationtest/org/apache/poi/TestAllFiles.java
src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java
src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java
src/java/org/apache/poi/hssf/record/RecordFactory.java
src/java/org/apache/poi/hssf/record/SupBookRecord.java
src/java/org/apache/poi/hssf/record/aggregates/SharedValueManager.java
src/java/org/apache/poi/ss/formula/function/FunctionMetadataReader.java
src/java/org/apache/poi/ss/formula/ptg/AbstractFunctionPtg.java
src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
src/testcases/org/apache/poi/hpsf/basic/TestBasic.java
src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java
src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java
src/testcases/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java

index 33bd696195f56712fa9c6415ce0558a9ef4d68fe..6daf088ac34f0bdc639a0d51c872222e69126458 100644 (file)
@@ -474,15 +474,15 @@ public class TestAllFiles {
 
     public static class NullFileHandler implements FileHandler {
         @Override
-        public void handleFile(InputStream stream, String path) throws Exception {
+        public void handleFile(InputStream stream, String path) {
         }
 
         @Override
-        public void handleExtracting(File file) throws Exception {
+        public void handleExtracting(File file) {
         }
 
         @Override
-        public void handleAdditional(File file) throws Exception {
+        public void handleAdditional(File file) {
         }
     }
 }
index 954163cb60064e0f3073b7ddc4be536a6861538e..a2a601ea1feacea5c9e5cbdaa0ba7fd4cae0505b 100644 (file)
@@ -117,11 +117,7 @@ public class DefaultEscherRecordFactory implements EscherRecordFactory {
             short sid;
             try {
                 sid = recCls.getField("RECORD_ID").getShort(null);
-            } catch (IllegalArgumentException e) {
-                throw new RuntimeException(e);
-            } catch (IllegalAccessException e) {
-                throw new RuntimeException(e);
-            } catch (NoSuchFieldException e) {
+            } catch (IllegalArgumentException | NoSuchFieldException | IllegalAccessException e) {
                 throw new RuntimeException(e);
             }
             Constructor<? extends EscherRecord> constructor;
index 28ee51f32b550188441f4781ff8357ed56d99286..55c32fb4f55743797ff444d386a80dc8accd8d2a 100644 (file)
@@ -276,7 +276,7 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p
 
        @Override
     public String getText() {
-               StringBuffer text = new StringBuffer();
+               StringBuilder text = new StringBuilder();
 
                // We don't care about the difference between
                //  null (missing) and blank cells
@@ -374,7 +374,7 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p
                                                        // Replace any newlines with spaces, otherwise it
                                                        //  breaks the output
                                                        String commentText = comment.getString().getString().replace('\n', ' ');
-                                                       text.append(" Comment by "+comment.getAuthor()+": "+commentText);
+                                                       text.append(" Comment by ").append(comment.getAuthor()).append(": ").append(commentText);
                                                }
                                        }
 
@@ -398,7 +398,7 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p
        }
 
        public static String _extractHeaderFooter(HeaderFooter hf) {
-               StringBuffer text = new StringBuffer();
+               StringBuilder text = new StringBuilder();
 
                if(hf.getLeft() != null) {
                        text.append(hf.getLeft());
index 8b5c0224c121dc834706b93117ad200bdfff0b0a..4bc14d68d394c3e2728b78a1c3dd2980a688228e 100644 (file)
@@ -82,11 +82,7 @@ public final class RecordFactory {
             Object[] args = { in, };
             try {
                 return _c.newInstance(args);
-            } catch (IllegalArgumentException e) {
-                throw new RuntimeException(e);
-            } catch (InstantiationException e) {
-                throw new RuntimeException(e);
-            } catch (IllegalAccessException e) {
+            } catch (IllegalArgumentException | IllegalAccessException | InstantiationException e) {
                 throw new RuntimeException(e);
             } catch (InvocationTargetException e) {
                 Throwable t = e.getTargetException();
@@ -118,9 +114,7 @@ public final class RecordFactory {
             Object[] args = { in, };
             try {
                 return (Record) _m.invoke(null, args);
-            } catch (IllegalArgumentException e) {
-                throw new RuntimeException(e);
-            } catch (IllegalAccessException e) {
+            } catch (IllegalArgumentException | IllegalAccessException e) {
                 throw new RuntimeException(e);
             } catch (InvocationTargetException e) {
                 throw new org.apache.poi.util.RecordFormatException("Unable to construct record instance" , e.getTargetException());
index bda7cca026569ef4773e8131342ac583a4667e14..32046669a60cff394746b0068f5fa184eb2c2fdc 100644 (file)
@@ -135,7 +135,7 @@ public final class SupBookRecord extends StandardRecord {
 
         if(isExternalReferences()) {
             sb.append("External References]\n");
-            sb.append(" .url     = ").append(field_2_encoded_url).append("\n");
+            sb.append(" .url     = ").append(getURL()).append("\n");
             sb.append(" .nSheets = ").append(field_1_number_of_sheets).append("\n");
             for (String sheetname : field_3_sheet_names) {
                 sb.append("    .name = ").append(sheetname).append("\n");
index ff12e1df8c3bb4141132f9f072e5f9ae8da0fe80..03de03ebbd94d9c9d2e18cdf424464b4b7475233 100644 (file)
@@ -18,6 +18,7 @@
 package org.apache.poi.hssf.record.aggregates;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -92,11 +93,9 @@ public final class SharedValueManager {
                }
 
                public final String toString() {
-                       StringBuffer sb = new StringBuffer(64);
-                       sb.append(getClass().getName()).append(" [");
-                       sb.append(_sfr.getRange());
-                       sb.append("]");
-                       return sb.toString();
+                       return getClass().getName() + " [" +
+                                       _sfr.getRange() +
+                                       "]";
                }
        }
 
@@ -135,9 +134,7 @@ public final class SharedValueManager {
         */
        private static <Z> List<Z> toList(Z[] zz) {
                List<Z> result = new ArrayList<>(zz.length);
-               for (int i = 0; i < zz.length; i++) {
-                       result.add(zz[i]);
-               }
+               Collections.addAll(result, zz);
                return result;
        }
 
index feea7d7b45e1b96593522db3ca29ac35b8c95109..dc6a8c025538d060099ff0263ce10470cded02af 100644 (file)
@@ -21,7 +21,6 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
 import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.HashSet;
@@ -146,9 +145,8 @@ final class FunctionMetadataReader {
 
        private static boolean isDash(String codes) {
                if(codes.length() == 1) {
-                       switch (codes.charAt(0)) {
-                               case '-':
-                                       return true;
+                       if (codes.charAt(0) == '-') {
+                               return true;
                        }
                }
                return false;
index 888868715789e01cff46f7d441306032034999af..28b5e7d9e54028584dd5d09cf4291c3191c33312 100644 (file)
@@ -59,12 +59,7 @@ public abstract class AbstractFunctionPtg extends OperationPtg {
     }
 
     public final String toString() {
-        StringBuilder sb = new StringBuilder(64);
-        sb.append(getClass().getName()).append(" [");
-        sb.append(lookupName(_functionIndex));
-        sb.append(" nArgs=").append(_numberOfArgs);
-        sb.append("]");
-        return sb.toString();
+        return getClass().getName() + " [" + lookupName(_functionIndex) + " nArgs=" + _numberOfArgs + "]";
     }
 
     public final short getFunctionIndex() {
index 42678983091da9d22c4d36d5f1cdc226c5e8f8bb..e1a7b2e9d3fda9474c4a43ffaf5d7a556c119e59 100644 (file)
@@ -799,8 +799,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
         XSSFSheet sheet = null;
         try {
             sheet = getWorkbook().getSheetAt(0);
-        } catch (InvalidFormatException ife) {
-        } catch (IOException ioe) {
+        } catch (InvalidFormatException | IOException ife) {
         }
         return sheet;
     }
index b3283ff1104d74aef14bf3a2f413f8920a19091d..8b9d15284863d23a5ce85f094e5f22288920f2a7 100644 (file)
@@ -192,9 +192,7 @@ public class XSLFGraphicFrame extends XSLFShape implements GraphicalFrame<XSLFSh
                 chartCopy.importContent(srcChart);
                 chartCopy.setWorkbook(srcChart.getWorkbook());
                 c.setAttributeText(idQualifiedName, slide.getRelationId(chartCopy));
-            } catch (InvalidFormatException e) {
-                throw new POIXMLException(e);
-            } catch (IOException e) {
+            } catch (InvalidFormatException | IOException e) {
                 throw new POIXMLException(e);
             }
             c.dispose();
index 819547ad284283d3f7d91f43c2ea4feb236f401e..8d1ce1a949363a62b4edc2b6e73438ef7171077d 100644 (file)
@@ -254,9 +254,7 @@ public class XSSFReader {
             XMLReader xmlReader;
             try {
                 xmlReader = SAXHelper.newXMLReader();
-            } catch (ParserConfigurationException e) {
-                throw new POIXMLException(e);
-            } catch (SAXException e) {
+            } catch (ParserConfigurationException | SAXException e) {
                 throw new POIXMLException(e);
             }
             xmlReader.setContentHandler(xmlSheetRefReader);
index 65e6d00dd18a56f70e3226f9f55fe1376ca7b447..04b4bea38f9ec26363799ad1d7495bbf115cf2d2 100644 (file)
@@ -1184,9 +1184,7 @@ public class XWPFRun implements ISDTContents, IRunElement, CharacterRun {
             docPr.setName("chart " + id);
 
             return inline;
-        } catch (XmlException e) {
-            throw new IllegalStateException(e);
-        } catch (SAXException e) {
+        } catch (XmlException | SAXException e) {
             throw new IllegalStateException(e);
         }
     }
index 45b130578aea0c0a58ffd43610e6ae15429d90f0..eb392080c28db361b84f1563ff246afd21dc2233 100644 (file)
@@ -56,45 +56,6 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
  * fixed, so that they are then run automatically.
  */
 public final class TestUnfixedBugs {
-    @Test
-    public void testBug54084Unicode() throws IOException {
-        // sample XLSX with the same text-contents as the text-file above
-        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("54084 - Greek - beyond BMP.xlsx");
-
-        verifyBug54084Unicode(wb);
-
-        //XSSFTestDataSamples.writeOut(wb, "bug 54084 for manual review");
-
-        // now write the file and read it back in
-        XSSFWorkbook wbWritten = XSSFTestDataSamples.writeOutAndReadBack(wb);
-        verifyBug54084Unicode(wbWritten);
-
-        // finally also write it out via the streaming interface and verify that we still can read it back in
-        SXSSFWorkbook swb = new SXSSFWorkbook(wb);
-        Workbook wbStreamingWritten = SXSSFITestDataProvider.instance.writeOutAndReadBack(swb);
-        verifyBug54084Unicode(wbStreamingWritten);
-
-        wbWritten.close();
-        swb.close();
-        wbStreamingWritten.close();
-        wb.close();
-    }
-
-    private void verifyBug54084Unicode(Workbook wb) {
-        // expected data is stored in UTF-8 in a text-file
-        byte[] data = HSSFTestDataSamples.getTestDataFileContent("54084 - Greek - beyond BMP.txt");
-        String testData = new String(data, StandardCharsets.UTF_8).trim();
-
-        Sheet sheet = wb.getSheetAt(0);
-        Row row = sheet.getRow(0);
-        Cell cell = row.getCell(0);
-
-        String value = cell.getStringCellValue();
-        //System.out.println(value);
-
-        assertEquals("The data in the text-file should exactly match the data that we read from the workbook", testData, value);
-    }
-
     @Test
     public void test54071() throws Exception {
         Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("54071.xlsx");
@@ -197,8 +158,7 @@ public final class TestUnfixedBugs {
 
     @Test
     public void testBug55752() throws IOException {
-        Workbook wb = new XSSFWorkbook();
-        try {
+        try (Workbook wb = new XSSFWorkbook()) {
             Sheet sheet = wb.createSheet("test");
 
             for (int i = 0; i < 4; i++) {
@@ -247,8 +207,6 @@ public final class TestUnfixedBugs {
 
             // write to file for manual inspection
             XSSFTestDataSamples.writeOut(wb, "bug 55752 for review");
-        } finally {
-            wb.close();
         }
     }
 
@@ -315,7 +273,7 @@ public final class TestUnfixedBugs {
         }
 
         // verify that the resulting XML has the rows in correct order as required by Excel
-        String xml = new String(stream.toByteArray(), "UTF-8");
+        String xml = new String(stream.toByteArray(), StandardCharsets.UTF_8);
         int posR12 = xml.indexOf("<row r=\"12\"");
         int posR13 = xml.indexOf("<row r=\"13\"");
 
index 9d94f8056867763fc8eaff6e35dcacfcc565b0ba..610ac7b22fba12849de3c85060982024bf06dcbf 100644 (file)
@@ -35,6 +35,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.Calendar;
 import java.util.HashMap;
@@ -116,6 +117,7 @@ import org.apache.poi.ss.util.CellUtil;
 import org.apache.poi.util.LocaleUtil;
 import org.apache.poi.util.NullOutputStream;
 import org.apache.poi.util.TempFile;
+import org.apache.poi.xssf.SXSSFITestDataProvider;
 import org.apache.poi.xssf.XLSBUnsupportedException;
 import org.apache.poi.xssf.XSSFITestDataProvider;
 import org.apache.poi.xssf.XSSFTestDataSamples;
@@ -3389,4 +3391,44 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
         assertEquals("E11", sheet.getActiveCell().formatAsString());
         wbBack.close();
     }
+
+    @Test
+    public void testBug54084Unicode() throws IOException {
+        // sample XLSX with the same text-contents as the text-file above
+        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("54084 - Greek - beyond BMP.xlsx");
+
+        verifyBug54084Unicode(wb);
+
+        //XSSFTestDataSamples.writeOut(wb, "bug 54084 for manual review");
+
+        // now write the file and read it back in
+        XSSFWorkbook wbWritten = XSSFTestDataSamples.writeOutAndReadBack(wb);
+        verifyBug54084Unicode(wbWritten);
+
+        // finally also write it out via the streaming interface and verify that we still can read it back in
+        SXSSFWorkbook swb = new SXSSFWorkbook(wb);
+        Workbook wbStreamingWritten = SXSSFITestDataProvider.instance.writeOutAndReadBack(swb);
+        verifyBug54084Unicode(wbStreamingWritten);
+
+        wbWritten.close();
+        swb.close();
+        wbStreamingWritten.close();
+        wb.close();
+    }
+
+    private void verifyBug54084Unicode(Workbook wb) {
+        // expected data is stored in UTF-8 in a text-file
+        byte[] data = HSSFTestDataSamples.getTestDataFileContent("54084 - Greek - beyond BMP.txt");
+        String testData = new String(data, StandardCharsets.UTF_8).trim();
+
+        Sheet sheet = wb.getSheetAt(0);
+        Row row = sheet.getRow(0);
+        Cell cell = row.getCell(0);
+
+        String value = cell.getStringCellValue();
+        //System.out.println(value);
+
+        assertEquals("The data in the text-file should exactly match the data that we read from the workbook", testData, value);
+    }
+
 }
index 0bc08772ed12d10400cff4309415f53ab1130666..13cce302516856579a85931be2243a359ad63de4 100644 (file)
@@ -123,9 +123,7 @@ public final class TestBasic {
             Object o;
             try {
                 o = PropertySetFactory.create(in);
-            } catch (NoPropertySetStreamException ex) {
-                o = ex;
-            } catch (MarkUnsupportedException ex) {
+            } catch (NoPropertySetStreamException | MarkUnsupportedException ex) {
                 o = ex;
             }
             in.close();
index 92e82d32e070ddf065f38c6555fd992b2c3739da..bdc7c5b6defd7d559355f61ad222904291d10395 100644 (file)
@@ -113,9 +113,7 @@ public final class TestEmptyProperties {
             Object o;
             try {
                 o = PropertySetFactory.create(in);
-            } catch (NoPropertySetStreamException ex) {
-                o = ex;
-            } catch (MarkUnsupportedException ex) {
+            } catch (NoPropertySetStreamException | MarkUnsupportedException ex) {
                 o = ex;
             }
             in.close();
index c6d4cca28860df5149972177d16573c3bb95b0d4..1fea921da605e636d09a2a60859b01436f8d5aee 100644 (file)
@@ -28,11 +28,8 @@ import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.util.RecordFormatException;
 import org.junit.Test;
 
-import junit.framework.AssertionFailedError;
-
 /**
  * @author aviks
  * 
@@ -43,100 +40,51 @@ import junit.framework.AssertionFailedError;
  * fixed, so that they are then run automatically.
  */
 public final class TestUnfixedBugs {
-
-    @Test
-       public void test43493() {
-               // Has crazy corrupt sub-records on
-               // a EmbeddedObjectRefSubRecord
-               try {
-                       HSSFTestDataSamples.openSampleWorkbook("43493.xls");
-               } catch (RecordFormatException e) {
-                       if (e.getCause().getCause() instanceof ArrayIndexOutOfBoundsException) {
-                               throw new AssertionFailedError("Identified bug 43493");
-                       }
-                       throw e;
-               }
-       }
-
-       /**
-        * Note - some parts of this bug have been fixed, and have been
-        * transfered over to {@link TestBugs#bug49612_part()}
-        */
-    @Test
-    public void test49612() throws IOException {
-        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49612.xls");
-        HSSFSheet sh = wb.getSheetAt(0);
-        HSSFRow row = sh.getRow(0);
-        HSSFCell c1 = row.getCell(2);
-        HSSFCell d1 = row.getCell(3);
-        HSSFCell e1 = row.getCell(2);
-
-        assertEquals("SUM(BOB+JIM)", c1.getCellFormula());
-
-        // Problem 1: Filename missing, see bug #56742
-        assertEquals("SUM('49612.xls'!BOB+'49612.xls'!JIM)", d1.getCellFormula());
-
-        //Problem 2: Filename missing, see bug #56742
-        //junit.framework.ComparisonFailure:
-        //Expected :SUM('49612.xls'!BOB+'49612.xls'!JIM)
-        //Actual   :SUM(BOB+JIM)
-        assertEquals("SUM('49612.xls'!BOB+'49612.xls'!JIM)", e1.getCellFormula());
-        
-        // Problem 3 - fixed and transfered
-        wb.close();
-    }
-
     @Test
     public void testFormulaRecordAggregate_1() throws Exception {
         // fails at formula "=MEHRFACH.OPERATIONEN(E$3;$B$5;$D4)"
-        Workbook wb = HSSFTestDataSamples.openSampleWorkbook("44958_1.xls");
-        try {
-            for(int i = 0;i < wb.getNumberOfSheets();i++) {
+        try (Workbook wb = HSSFTestDataSamples.openSampleWorkbook("44958_1.xls")) {
+            for (int i = 0; i < wb.getNumberOfSheets(); i++) {
                 Sheet sheet = wb.getSheetAt(i);
                 assertNotNull(wb.getSheet(sheet.getSheetName()));
                 sheet.groupColumn((short) 4, (short) 5);
                 sheet.setColumnGroupCollapsed(4, true);
                 sheet.setColumnGroupCollapsed(4, false);
-                
-                for(Row row : sheet) {
-                    for(Cell cell : row) {
+
+                for (Row row : sheet) {
+                    for (Cell cell : row) {
                         try {
-                            cell.toString();
+                            assertNotNull(cell.toString());
                         } catch (Exception e) {
                             throw new Exception("While handling: " + sheet.getSheetName() + "/" + row.getRowNum() + "/" + cell.getColumnIndex(), e);
                         }
                     }
                 }
             }
-        } finally {
-            wb.close();
         }
     }
 
     @Test
     public void testFormulaRecordAggregate() throws Exception {
         // fails at formula "=MEHRFACH.OPERATIONEN(E$3;$B$5;$D4)"
-        Workbook wb = HSSFTestDataSamples.openSampleWorkbook("44958.xls");
-        try {
-            for(int i = 0;i < wb.getNumberOfSheets();i++) {
+        try (Workbook wb = HSSFTestDataSamples.openSampleWorkbook("44958.xls")) {
+            for (int i = 0; i < wb.getNumberOfSheets(); i++) {
                 Sheet sheet = wb.getSheetAt(i);
                 assertNotNull(wb.getSheet(sheet.getSheetName()));
                 sheet.groupColumn((short) 4, (short) 5);
                 sheet.setColumnGroupCollapsed(4, true);
                 sheet.setColumnGroupCollapsed(4, false);
-                
-                for(Row row : sheet) {
-                    for(Cell cell : row) {
+
+                for (Row row : sheet) {
+                    for (Cell cell : row) {
                         try {
-                            cell.toString();
+                            assertNotNull(cell.toString());
                         } catch (Exception e) {
                             throw new Exception("While handling: " + sheet.getSheetName() + "/" + row.getRowNum() + "/" + cell.getColumnIndex(), e);
                         }
                     }
                 }
-            } 
-        } finally {
-            wb.close();
+            }
         }
     }
 
index 173ccb7d9cc6288f08b490b585212918ffb58e01..fe868dbdd92274c72f70c44e3af23c98403b1d6d 100644 (file)
@@ -449,9 +449,7 @@ public final class ExcelFileFormatDocFunctionExtractor {
                try {
                        xr.parse(inSrc);
                        is.close();
-               } catch (IOException e) {
-                       throw new RuntimeException(e);
-               } catch (SAXException e) {
+               } catch (IOException | SAXException e) {
                        throw new RuntimeException(e);
                }
        }
@@ -521,8 +519,6 @@ public final class ExcelFileFormatDocFunctionExtractor {
                        InputStream is = zf.getInputStream(zf.getEntry("content.xml"));
                        extractFunctionData(new FunctionDataCollector(ps), is);
                        zf.close();
-               } catch (ZipException e) {
-                       throw new RuntimeException(e);
                } catch (IOException e) {
                        throw new RuntimeException(e);
                }