You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2020/01/27 22:54:03 UTC

svn commit: r1873231 - in /poi/trunk/src: ooxml/java/org/apache/poi/xddf/usermodel/chart/ ooxml/java/org/apache/poi/xssf/usermodel/ ooxml/testcases/org/apache/poi/openxml4j/opc/ ooxml/testcases/org/apache/poi/xslf/usermodel/ ooxml/testcases/org/apache/...

Author: centic
Date: Mon Jan 27 22:54:03 2020
New Revision: 1873231

URL: http://svn.apache.org/viewvc?rev=1873231&view=rev
Log:
Fix some IDE warnings, Sonar fixes and some missing closing of resources in unit-tests

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfPicture.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java?rev=1873231&r1=1873230&r2=1873231&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java Mon Jan 27 22:54:03 2020
@@ -588,14 +588,7 @@ public abstract class XDDFChart extends
 
     public XDDFValueAxis createValueAxis(AxisPosition pos) {
         XDDFValueAxis valueAxis = new XDDFValueAxis(getCTPlotArea(), pos);
-        if (axes.size() == 1) {
-            XDDFChartAxis axis = axes.get(0);
-            axis.crossAxis(valueAxis);
-            valueAxis.crossAxis(axis);
-            axis.setCrosses(AxisCrosses.AUTO_ZERO);
-            valueAxis.setCrosses(AxisCrosses.AUTO_ZERO);
-        }
-        axes.add(valueAxis);
+        addAxis(valueAxis);
         return valueAxis;
     }
 
@@ -607,41 +600,31 @@ public abstract class XDDFChart extends
      */
     public XDDFSeriesAxis createSeriesAxis(AxisPosition pos) {
         XDDFSeriesAxis seriesAxis = new XDDFSeriesAxis(getCTPlotArea(), pos);
-        if (axes.size() == 1) {
-            XDDFChartAxis axis = axes.get(0);
-            axis.crossAxis(seriesAxis);
-            seriesAxis.crossAxis(axis);
-            axis.setCrosses(AxisCrosses.AUTO_ZERO);
-            seriesAxis.setCrosses(AxisCrosses.AUTO_ZERO);
-        }
-        axes.add(seriesAxis);
+        addAxis(seriesAxis);
         return seriesAxis;
     }
 
     public XDDFCategoryAxis createCategoryAxis(AxisPosition pos) {
         XDDFCategoryAxis categoryAxis = new XDDFCategoryAxis(getCTPlotArea(), pos);
-        if (axes.size() == 1) {
-            XDDFChartAxis axis = axes.get(0);
-            axis.crossAxis(categoryAxis);
-            categoryAxis.crossAxis(axis);
-            axis.setCrosses(AxisCrosses.AUTO_ZERO);
-            categoryAxis.setCrosses(AxisCrosses.AUTO_ZERO);
-        }
-        axes.add(categoryAxis);
+        addAxis(categoryAxis);
         return categoryAxis;
     }
 
     public XDDFDateAxis createDateAxis(AxisPosition pos) {
         XDDFDateAxis dateAxis = new XDDFDateAxis(getCTPlotArea(), pos);
+        addAxis(dateAxis);
+        return dateAxis;
+    }
+
+    private void addAxis(XDDFChartAxis newAxis) {
         if (axes.size() == 1) {
             XDDFChartAxis axis = axes.get(0);
-            axis.crossAxis(dateAxis);
-            dateAxis.crossAxis(axis);
+            axis.crossAxis(newAxis);
+            newAxis.crossAxis(axis);
             axis.setCrosses(AxisCrosses.AUTO_ZERO);
-            dateAxis.setCrosses(AxisCrosses.AUTO_ZERO);
+            newAxis.setCrosses(AxisCrosses.AUTO_ZERO);
         }
-        axes.add(dateAxis);
-        return dateAxis;
+        axes.add(newAxis);
     }
 
     /**
@@ -774,7 +757,7 @@ public abstract class XDDFChart extends
     public PackageRelationship createRelationshipInChart(POIXMLRelation chartRelation, POIXMLFactory chartFactory,
         int chartIndex) {
         documentPart = createRelationship(chartRelation, chartFactory, chartIndex, true).getDocumentPart();
-        return this.addRelation(null, chartRelation, documentPart).getRelationship();
+        return addRelation(null, chartRelation, documentPart).getRelationship();
     }
 
     /**
@@ -793,7 +776,7 @@ public abstract class XDDFChart extends
     private PackagePart createWorksheetPart(POIXMLRelation chartRelation, POIXMLRelation chartWorkbookRelation,
         POIXMLFactory chartFactory) throws InvalidFormatException {
         PackageRelationship xlsx = createRelationshipInChart(chartWorkbookRelation, chartFactory, chartIndex);
-        this.setExternalId(xlsx.getId());
+        setExternalId(xlsx.getId());
         return getTargetPart(xlsx);
     }
 
@@ -859,14 +842,14 @@ public abstract class XDDFChart extends
     protected void fillSheet(XSSFSheet sheet, XDDFDataSource<?> categoryData, XDDFNumericalDataSource<?> valuesData) {
         int numOfPoints = categoryData.getPointCount();
         for (int i = 0; i < numOfPoints; i++) {
-            XSSFRow row = this.getRow(sheet, i + 1); // first row is for title
+            XSSFRow row = getRow(sheet, i + 1); // first row is for title
             Object category = categoryData.getPointAt(i);
             if (category != null) {
-                this.getCell(row, categoryData.getColIndex()).setCellValue(category.toString());
+                getCell(row, categoryData.getColIndex()).setCellValue(category.toString());
             }
             Number value = valuesData.getPointAt(i);
             if (value != null) {
-                this.getCell(row, valuesData.getColIndex()).setCellValue(value.doubleValue());
+                getCell(row, valuesData.getColIndex()).setCellValue(value.doubleValue());
             }
         }
     }
@@ -956,8 +939,8 @@ public abstract class XDDFChart extends
      */
     public CellReference setSheetTitle(String title, int column) {
         XSSFSheet sheet = getSheet();
-        XSSFRow row = this.getRow(sheet, 0);
-        XSSFCell cell = this.getCell(row, column);
+        XSSFRow row = getRow(sheet, 0);
+        XSSFCell cell = getCell(row, column);
         cell.setCellValue(title);
 
         return new CellReference(sheet.getSheetName(), 0, column, true, true);

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java?rev=1873231&r1=1873230&r2=1873231&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java Mon Jan 27 22:54:03 2020
@@ -99,7 +99,7 @@ public class XSSFFont implements Font {
         setFontName(DEFAULT_FONT_NAME);
         setFontHeight((double)DEFAULT_FONT_SIZE);
     }
-    
+
     /**
      * get the underlying CTFont font
      */
@@ -209,7 +209,7 @@ public class XSSFFont implements Font {
     public short getFontHeightInPoints() {
         return (short)getFontHeightRaw();
     }
-    
+
     /**
      * Return the raw font height, in points, but also
      *  including fractions.
@@ -540,7 +540,7 @@ public class XSSFFont implements Font {
 
 
     /**
-     * Perform a registration of ourselves 
+     * Perform a registration of ourselves
      *  to the style table
      */
     public long registerTo(StylesTable styles) {
@@ -649,7 +649,7 @@ public class XSSFFont implements Font {
                         && Objects.equals(this.getBold(), cf.getBold())
                         && Objects.equals(this.getStrikeout(), cf.getStrikeout())
                         && Objects.equals(this.getCharSet(), cf.getCharSet())
-                        && Objects.equals(this.getBold(), cf.getBold())
+                        && Objects.equals(this.getItalic(), cf.getItalic())
                         && Objects.equals(this.getColor(), cf.getColor())
                         && Objects.equals(this.getFamily(), cf.getFamily())
                         && Objects.equals(this.getFontHeight(), cf.getFontHeight())

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java?rev=1873231&r1=1873230&r2=1873231&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java Mon Jan 27 22:54:03 2020
@@ -79,6 +79,7 @@ import java.io.OutputStream;
 import java.io.PushbackInputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -86,7 +87,6 @@ import java.util.List;
 import java.util.TreeMap;
 import java.util.function.BiConsumer;
 import java.util.regex.Pattern;
-import java.util.zip.ZipException;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -113,7 +113,7 @@ public final class TestPackage {
         OPCPackage p = OPCPackage.open(originalFile, PackageAccess.READ_WRITE);
 		try {
     		p.save(targetFile.getAbsoluteFile());
-    
+
     		// Compare the original and newly saved document
     		assertTrue(targetFile.exists());
     		ZipFileAssert.assertEquals(new File(originalFile), targetFile);
@@ -160,7 +160,7 @@ public final class TestPackage {
 						PackagingURIHelper.createPartName("/foo.txt")
 				)
 		);
-		
+
 		pkg.revert();
 	}
 
@@ -229,7 +229,7 @@ public final class TestPackage {
         PackagePart corePart = pkg.createPart(corePartName, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml");
         // Put in some dummy content
         OutputStream coreOut = corePart.getOutputStream();
-        coreOut.write("<dummy-xml />".getBytes("UTF-8"));
+        coreOut.write("<dummy-xml />".getBytes(StandardCharsets.UTF_8));
         coreOut.close();
 
 		// And another bit
@@ -243,7 +243,7 @@ public final class TestPackage {
 
         // Dummy content again
         coreOut = corePart.getOutputStream();
-        coreOut.write("<dummy-xml2 />".getBytes("UTF-8"));
+        coreOut.write("<dummy-xml2 />".getBytes(StandardCharsets.UTF_8));
         coreOut.close();
 
         //add a relationship with internal target: "#Sheet1!A1"
@@ -280,13 +280,13 @@ public final class TestPackage {
             assertEquals("/xl/workbook.xml", coreRel.getTargetURI().toString());
             corePart = pkg.getPart(coreRel);
             assertNotNull(corePart);
-    
+
             PackageRelationshipCollection rels = corePart.getRelationshipsByType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink");
             assertEquals(1, rels.size());
             rel = rels.getRelationship(0);
 			assertNotNull(rel);
             assertEquals("Sheet1!A1", rel.getTargetURI().getRawFragment());
-    
+
             assertMSCompatibility(pkg);
         } finally {
             pkg.close();
@@ -384,7 +384,7 @@ public final class TestPackage {
 			try (FileOutputStream fout = new FileOutputStream(targetFile)) {
 				p.save(fout);
 			}
-    
+
     		// Compare the original and newly saved document
     		assertTrue(targetFile.exists());
     		ZipFileAssert.assertEquals(new File(originalFile), targetFile);
@@ -404,28 +404,29 @@ public final class TestPackage {
 	public void openFromInputStream() throws IOException, InvalidFormatException {
 		String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");
 
-		FileInputStream finp = new FileInputStream(originalFile);
-
-		@SuppressWarnings("resource")
-        OPCPackage p = OPCPackage.open(finp);
-
-		assertNotNull(p);
-		assertNotNull(p.getRelationships());
-		assertEquals(12, p.getParts().size());
-
-		// Check it has the usual bits
-		assertTrue(p.hasRelationships());
-		assertTrue(p.containPart(PackagingURIHelper.createPartName("/_rels/.rels")));
-		
-		p.revert();
-		finp.close();
+		try (FileInputStream finp = new FileInputStream(originalFile)) {
+			@SuppressWarnings("resource")
+			OPCPackage p = OPCPackage.open(finp);
+
+			try {
+				assertNotNull(p);
+				assertNotNull(p.getRelationships());
+				assertEquals(12, p.getParts().size());
+
+				// Check it has the usual bits
+				assertTrue(p.hasRelationships());
+				assertTrue(p.containPart(PackagingURIHelper.createPartName("/_rels/.rels")));
+			} finally {
+				p.revert();
+			}
+		}
 	}
 
     /**
      * TODO: fix and enable
      */
     @Test
-    @Ignore
+	@Ignore
     public void removePartRecursive() throws IOException, InvalidFormatException, URISyntaxException {
 		String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");
 		File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageRemovePartRecursiveOUTPUT.docx");
@@ -433,16 +434,18 @@ public final class TestPackage {
 
 		@SuppressWarnings("resource")
         OPCPackage p = OPCPackage.open(originalFile, PackageAccess.READ_WRITE);
-		p.removePartRecursive(PackagingURIHelper.createPartName(new URI(
-				"/word/document.xml")));
-		p.save(tempFile.getAbsoluteFile());
-
-		// Compare the original and newly saved document
-		assertTrue(targetFile.exists());
-		ZipFileAssert.assertEquals(targetFile, tempFile);
-		assertTrue(targetFile.delete());
-		
-		p.revert();
+		try {
+			p.removePartRecursive(PackagingURIHelper.createPartName(new URI(
+					"/word/document.xml")));
+			p.save(tempFile.getAbsoluteFile());
+
+			// Compare the original and newly saved document
+			assertTrue(targetFile.exists());
+			ZipFileAssert.assertEquals(targetFile, tempFile);
+			assertTrue(targetFile.delete());
+		} finally {
+			p.revert();
+		}
 	}
 
     @Test
@@ -543,7 +546,7 @@ public final class TestPackage {
 		// Don't save modifications
 		p.revert();
 	}
-	
+
 	/**
 	 * Test that we can open a file by path, and then
 	 *  write changes to it.
@@ -553,18 +556,18 @@ public final class TestPackage {
         File tempFile = TempFile.createTempFile("poiTesting","tmp");
         File origFile = OpenXML4JTestDataSamples.getSampleFile("TestPackageCommon.docx");
         FileHelper.copyFile(origFile, tempFile);
-        
+
         // Open the temp file
         OPCPackage p = OPCPackage.open(tempFile.toString(), PackageAccess.READ_WRITE);
         // Close it
         p.close();
         // Delete it
         assertTrue(tempFile.delete());
-        
+
         // Reset
         FileHelper.copyFile(origFile, tempFile);
         p = OPCPackage.open(tempFile.toString(), PackageAccess.READ_WRITE);
-        
+
         // Save it to the same file - not allowed
         try {
             p.save(tempFile);
@@ -576,14 +579,15 @@ public final class TestPackage {
         p.close();
         // Delete it
         assertTrue(tempFile.delete());
-        
-        
+
+
         // Open it read only, then close and delete - allowed
         FileHelper.copyFile(origFile, tempFile);
         p = OPCPackage.open(tempFile.toString(), PackageAccess.READ);
         p.close();
         assertTrue(tempFile.delete());
 	}
+
     /**
      * Test that we can open a file by path, save it
      *  to another file, then delete both
@@ -594,14 +598,13 @@ public final class TestPackage {
         File tempFile2 = TempFile.createTempFile("poiTesting","tmp");
         File origFile = OpenXML4JTestDataSamples.getSampleFile("TestPackageCommon.docx");
         FileHelper.copyFile(origFile, tempFile);
-        
+
         // Open the temp file
-        OPCPackage p = OPCPackage.open(tempFile.toString(), PackageAccess.READ_WRITE);
+		try (OPCPackage p = OPCPackage.open(tempFile.toString(), PackageAccess.READ_WRITE)) {
+			// Save it to a different file
+			p.save(tempFile2);
+		}
 
-        // Save it to a different file
-        p.save(tempFile2);
-        p.close();
-        
         // Delete both the files
         assertTrue(tempFile.delete());
         assertTrue(tempFile2.delete());
@@ -620,10 +623,10 @@ public final class TestPackage {
         try {
             List<PackagePart> rs =  pkg.getPartsByName(Pattern.compile("/word/.*?\\.xml"));
             HashMap<String, PackagePart>  selected = new HashMap<>();
-    
+
             for(PackagePart p : rs)
                 selected.put(p.getPartName().getName(), p);
-    
+
             assertEquals(6, selected.size());
             assertTrue(selected.containsKey("/word/document.xml"));
             assertTrue(selected.containsKey("/word/fontTable.xml"));
@@ -636,7 +639,7 @@ public final class TestPackage {
             pkg.revert();
         }
     }
-    
+
     @Test
     public void getPartSize() throws IOException, InvalidFormatException {
        String filepath =  OpenXML4JTestDataSamples.getSampleFileName("sample.docx");
@@ -690,7 +693,7 @@ public final class TestPackage {
         p.revert();
         is.close();
     }
-    
+
     /**
      * Verify we give helpful exceptions (or as best we can) when
      *  supplied with non-OOXML file types (eg OLE2, ODF)
@@ -699,7 +702,7 @@ public final class TestPackage {
     public void NonOOXMLFileTypes() throws Exception {
         // Spreadsheet has a good mix of alternate file types
         POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
-        
+
         // OLE2 - Stream
         try {
 			try (InputStream stream = files.openResourceAsStream("SampleSS.xls")) {
@@ -718,7 +721,7 @@ public final class TestPackage {
             assertTrue(e.getMessage().contains("The supplied data appears to be in the OLE2 Format"));
             assertTrue(e.getMessage().contains("You are calling the part of POI that deals with OOXML"));
         }
-        
+
         // Raw XML - Stream
         try {
 			try (InputStream stream = files.openResourceAsStream("SampleSS.xml")) {
@@ -737,7 +740,7 @@ public final class TestPackage {
             assertTrue(e.getMessage().contains("The supplied data appears to be a raw XML file"));
             assertTrue(e.getMessage().contains("Formats such as Office 2003 XML"));
         }
-        
+
         // ODF / ODS - Stream
         try {
 			try (InputStream stream = files.openResourceAsStream("SampleSS.ods")) {
@@ -756,7 +759,7 @@ public final class TestPackage {
             assertTrue(e.toString().contains("The supplied data appears to be in ODF"));
             assertTrue(e.toString().contains("Formats like these (eg ODS"));
         }
-        
+
         // Plain Text - Stream
         try {
 			try (InputStream stream = files.openResourceAsStream("SampleSS.txt")) {
@@ -814,7 +817,7 @@ public final class TestPackage {
 								append.write(spam);
 								size += spam.length;
 							}
-							append.write("</Types>".getBytes("UTF-8"));
+							append.write("</Types>".getBytes(StandardCharsets.UTF_8));
 							size += 8;
 							eOut.setSize(size);
 						} else {
@@ -969,7 +972,7 @@ public final class TestPackage {
             ZipSecureFile.setMaxTextSize(before);
         }
     }
-    
+
     // bug 60128
     @Test(expected=NotOfficeXmlFileException.class)
     public void testCorruptFile() throws InvalidFormatException {
@@ -989,7 +992,7 @@ public final class TestPackage {
                 new PushbackInputStream(new FileInputStream(hssf), 2),
                 new BufferedInputStream(new FileInputStream(hssf), 2),
         };
-        
+
         try {
             for (InputStream is : isList) {
                 WorkbookFactory.create(is).close();
@@ -1099,9 +1102,10 @@ public final class TestPackage {
 	public void testBug62592SequentialCallsToGetParts() throws Exception {
 		//make absolutely certain that sequential calls don't throw InvalidFormatExceptions
 		String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");
-		OPCPackage p2 = OPCPackage.open(originalFile, PackageAccess.READ);
-		p2.getParts();
-		p2.getParts();
+		try (OPCPackage p2 = OPCPackage.open(originalFile, PackageAccess.READ)) {
+			p2.getParts();
+			p2.getParts();
+		}
 	}
 
 	@Test
@@ -1189,6 +1193,7 @@ public final class TestPackage {
 		}
 	}
 
+	@SuppressWarnings("UnstableApiUsage")
 	@Test
 	public void testBug63029() throws Exception {
 		File testFile = OpenXML4JTestDataSamples.getSampleFile("sample.docx");
@@ -1212,6 +1217,7 @@ public final class TestPackage {
 			ex = e;
 		}
 		// verify there was an exception while closing the file
+		assertNotNull("Fail to save: an error occurs while saving the package : Bugzilla 63029", ex);
 		assertEquals("Fail to save: an error occurs while saving the package : Bugzilla 63029", ex.getMessage());
 
 		// assert that md5 after closing is the same, i.e. the source is left intact

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java?rev=1873231&r1=1873230&r2=1873231&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java Mon Jan 27 22:54:03 2020
@@ -49,8 +49,6 @@ public class TestPPTX2PNG {
         "backgrounds.pptx, layouts.pptx, sample.pptx, shapes.pptx, 54880_chinese.ppt, keyframes.pptx," +
         "customGeo.pptx, customGeo.ppt, wrench.emf, santa.wmf";
 
-
-
     @BeforeClass
     public static void checkHslf() {
         try {
@@ -61,7 +59,7 @@ public class TestPPTX2PNG {
     }
 
     // use filename instead of File object to omit full pathname in test name
-    @Parameter(value = 0)
+    @Parameter
     public String pptFile;
 
     @SuppressWarnings("ConstantConditions")

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java?rev=1873231&r1=1873230&r2=1873231&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java Mon Jan 27 22:54:03 2020
@@ -234,12 +234,13 @@ public final class TestSharedStringsTabl
 
         Path path = XSSFTestDataSamples.getSampleFile("48936-strings.txt").toPath();
 
-        Stream<String> lines = Files.lines(path, StandardCharsets.UTF_8);
-        List<String> lst = lines
-            .map(String::trim)
-            .filter(((Predicate<String>)String::isEmpty).negate())
-            .collect(Collectors.toList());
-        lines.close();
+        final List<String> lst;
+        try (Stream<String> lines = Files.lines(path, StandardCharsets.UTF_8)) {
+            lst = lines
+                    .map(String::trim)
+                    .filter(((Predicate<String>) String::isEmpty).negate())
+                    .collect(Collectors.toList());
+        }
 
         for (String str : lst) {
             s.createRow(i++).createCell(0).setCellValue(str);

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1873231&r1=1873230&r2=1873231&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Mon Jan 27 22:54:03 2020
@@ -1919,29 +1919,31 @@ public final class TestXSSFBugs extends
     @Test
     public void test54764WithSAXHelper() throws Exception {
         File testFile = XSSFTestDataSamples.getSampleFile("54764.xlsx");
-        ZipFile zip = new ZipFile(testFile);
-        ZipArchiveEntry ze = zip.getEntry("xl/sharedStrings.xml");
-        XMLReader reader = XMLHelper.newXMLReader();
-        try {
-            reader.parse(new InputSource(zip.getInputStream(ze)));
-            fail("should have thrown SAXParseException");
-        } catch (SAXParseException e) {
-            assertNotNull(e.getMessage());
-            assertTrue(e.getMessage().contains("more than \"1\" entity"));
+        try (ZipFile zip = new ZipFile(testFile)) {
+            ZipArchiveEntry ze = zip.getEntry("xl/sharedStrings.xml");
+            XMLReader reader = XMLHelper.newXMLReader();
+            try {
+                reader.parse(new InputSource(zip.getInputStream(ze)));
+                fail("should have thrown SAXParseException");
+            } catch (SAXParseException e) {
+                assertNotNull(e.getMessage());
+                assertTrue(e.getMessage().contains("more than \"1\" entity"));
+            }
         }
     }
 
     @Test
     public void test54764WithDocumentHelper() throws Exception {
         File testFile = XSSFTestDataSamples.getSampleFile("54764.xlsx");
-        ZipFile zip = new ZipFile(testFile);
-        ZipArchiveEntry ze = zip.getEntry("xl/sharedStrings.xml");
-        try {
-            DocumentHelper.readDocument(zip.getInputStream(ze));
-            fail("should have thrown SAXParseException");
-        } catch (SAXParseException e) {
-            assertNotNull(e.getMessage());
-            assertNotEquals(isOldXercesActive(), e.getMessage().contains("DOCTYPE is disallowed when the feature"));
+        try (ZipFile zip = new ZipFile(testFile)) {
+            ZipArchiveEntry ze = zip.getEntry("xl/sharedStrings.xml");
+            try {
+                DocumentHelper.readDocument(zip.getInputStream(ze));
+                fail("should have thrown SAXParseException");
+            } catch (SAXParseException e) {
+                assertNotNull(e.getMessage());
+                assertNotEquals(isOldXercesActive(), e.getMessage().contains("DOCTYPE is disallowed when the feature"));
+            }
         }
     }
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java?rev=1873231&r1=1873230&r2=1873231&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java Mon Jan 27 22:54:03 2020
@@ -103,7 +103,7 @@ public final class TestXSSFFont extends
         assertEquals(FontCharset.ARABIC.getValue(), xssfFont.getCharSet());
         xssfFont.setCharSet((byte)(FontCharset.ARABIC.getValue()));
         assertEquals(FontCharset.ARABIC.getValue(), xssfFont.getCharSet());
-        
+
         // This one isn't allowed
         assertNull(FontCharset.valueOf(9999));
         try {
@@ -112,20 +112,20 @@ public final class TestXSSFFont extends
         } catch(POIXMLException e) {
         	// expected here
 		}
-      
-		
+
+
 		// Now try with a few sample files
-		
+
 		// Normal charset
         XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
-        assertEquals(0, 
+        assertEquals(0,
               wb1.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFont().getCharSet()
         );
         wb1.close();
-		
+
 		// GB2312 charset
         XSSFWorkbook wb2 = XSSFTestDataSamples.openSampleWorkbook("49273.xlsx");
-        assertEquals(134, 
+        assertEquals(134,
               wb2.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFont().getCharSet()
         );
         wb2.close();
@@ -253,13 +253,13 @@ public final class TestXSSFFont extends
 		assertEquals(ctFont.getColorArray(0).getRgb()[3],xssfFont.getXSSFColor().getRGB()[3]);
 
 		xssfFont.setColor((short)23);
-		
+
 		byte[] bytes = Integer.toHexString(0xF1F1F1).getBytes(LocaleUtil.CHARSET_1252);
         color.setRgb(bytes);
 		XSSFColor newColor=XSSFColor.from(color, null);
 		xssfFont.setColor(newColor);
 		assertEquals(ctFont.getColorArray(0).getRgb()[2],newColor.getRGB()[2]);
-		
+
 		assertArrayEquals(bytes, xssfFont.getXSSFColor().getRGB());
 		assertEquals(0, xssfFont.getColor());
 	}
@@ -325,16 +325,16 @@ public final class TestXSSFFont extends
         // cannot check on result because on some machines we get back false here!
         SheetUtil.canComputeColumnWidth(wb.getFontAt(0));
 
-        wb.close();        
+        wb.close();
     }
 
     // store test from TestSheetUtil here as it uses XSSF
 	@Test
-	public void testCanComputeWidthInvalidFont() throws IOException {
+	public void testCanComputeWidthInvalidFont() {
         Font font = new XSSFFont(CTFont.Factory.newInstance());
         font.setFontName("some non existing font name");
-        
-        // Even with invalid fonts we still get back useful data most of the time... 
+
+        // Even with invalid fonts we still get back useful data most of the time...
         SheetUtil.canComputeColumnWidth(font);
     }
 
@@ -439,4 +439,19 @@ public final class TestXSSFFont extends
 
 		wb.close();
 	}
+
+	@Test
+	public void testEquals() {
+		XSSFFont font = new XSSFFont();
+		XSSFFont equ = new XSSFFont();
+		XSSFFont notequ = new XSSFFont();
+		notequ.setItalic(true);
+
+		assertEquals(equ, font);
+		assertNotEquals(font, notequ);
+
+		notequ.setItalic(false);
+		notequ.setThemeColor((short)123);
+		assertNotEquals(font, notequ);
+	}
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfPicture.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfPicture.java?rev=1873231&r1=1873230&r2=1873231&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfPicture.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfPicture.java Mon Jan 27 22:54:03 2020
@@ -25,7 +25,6 @@ import java.awt.Shape;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Dimension2D;
 import java.awt.geom.Rectangle2D;
-import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -57,11 +56,11 @@ public class HemfPicture implements Iter
     private final List<HemfRecord> records = new ArrayList<>();
     private boolean isParsed = false;
 
-    public HemfPicture(InputStream is) throws IOException {
+    public HemfPicture(InputStream is) {
         this(new LittleEndianInputStream(is));
     }
 
-    public HemfPicture(LittleEndianInputStream is) throws IOException {
+    public HemfPicture(LittleEndianInputStream is) {
         stream = is;
     }
 
@@ -175,13 +174,11 @@ public class HemfPicture implements Iter
             prop.setViewportOrg(emfBounds.getX(), emfBounds.getY());
             prop.setViewportExt(emfBounds.getWidth(), emfBounds.getHeight());
 
-            int idx = 0;
             for (HemfRecord r : getRecords()) {
                 try {
                     g.draw(r);
                 } catch (RuntimeException ignored) {
                 }
-                idx++;
             }
         } finally {
             ctx.setTransform(at);

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java?rev=1873231&r1=1873230&r2=1873231&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java Mon Jan 27 22:54:03 2020
@@ -59,6 +59,10 @@ public class OutlookTextExtractor extend
     }
 
     public static void main(String[] args) throws Exception {
+        if(args.length == 0) {
+            System.err.println("Usage: OutlookTextExtractor <file> [<file> ...]");
+            System.exit(1);
+        }
         for (String filename : args) {
             try (POIFSFileSystem poifs = new POIFSFileSystem(new File(filename));
                  OutlookTextExtractor extractor = new OutlookTextExtractor(poifs)) {

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java?rev=1873231&r1=1873230&r2=1873231&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java Mon Jan 27 22:54:03 2020
@@ -94,7 +94,7 @@ public final class CharacterSprmCompress
 
        size += SprmUtils.addSprm((short)0x6a09, 0, varParam, sprmList);
     }
-    if (newCHP.isFOle2() != newCHP.isFOle2())
+    if (newCHP.isFOle2() != oldCHP.isFOle2())
     {
       int value = 0;
       if (newCHP.isFOle2())



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org