From ceae0d0903e95dbf0c9e70a7e154513232e529c9 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Fri, 25 Sep 2020 19:39:45 +0000 Subject: [PATCH] Fix IDE warnings, add more assertion-output git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1882025 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/stress/HPSFFileHandler.java | 5 +-- .../org/apache/poi/stress/OPCFileHandler.java | 8 ++-- .../apache/poi/stress/XSLFFileHandler.java | 6 +-- .../org/apache/poi/ooxml/POIXMLRelation.java | 6 +-- .../apache/poi/ooxml/TestPOIXMLDocument.java | 38 +++++++++---------- 5 files changed, 29 insertions(+), 34 deletions(-) diff --git a/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java b/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java index dbbbea66a7..d01b0a3cba 100644 --- a/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java +++ b/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java @@ -33,7 +33,6 @@ import java.util.Set; import org.apache.poi.examples.hpsf.CopyCompare; import org.apache.poi.hpsf.DocumentSummaryInformation; import org.apache.poi.hpsf.HPSFPropertiesOnlyDocument; -import org.apache.poi.hpsf.MarkUnsupportedException; import org.apache.poi.hpsf.PropertySet; import org.apache.poi.hpsf.SummaryInformation; import org.apache.poi.poifs.filesystem.DirectoryNode; @@ -85,7 +84,7 @@ public class HPSFFileHandler extends POIFSFileHandler { handlePOIDocument(hpsf); } - private static boolean hasPropertyStream(POIFSFileSystem poifs, String streamName) throws IOException, MarkUnsupportedException { + private static boolean hasPropertyStream(POIFSFileSystem poifs, String streamName) throws IOException { DirectoryNode root = poifs.getRoot(); if (!root.hasEntry(streamName)) { return false; @@ -121,7 +120,7 @@ public class HPSFFileHandler extends POIFSFileHandler { @Test @SuppressWarnings("java:S2699") public void test() throws Exception { - String path = "test-data/hpsf/Test0313rur.adm"; + String path = "test-data/diagram/44501.vsd"; try (InputStream stream = new FileInputStream(path)) { handleFile(stream, path); } diff --git a/src/integrationtest/org/apache/poi/stress/OPCFileHandler.java b/src/integrationtest/org/apache/poi/stress/OPCFileHandler.java index fe0d547ebb..59c352c129 100644 --- a/src/integrationtest/org/apache/poi/stress/OPCFileHandler.java +++ b/src/integrationtest/org/apache/poi/stress/OPCFileHandler.java @@ -43,7 +43,7 @@ public class OPCFileHandler extends AbstractFileHandler { assertEquals(ContentTypes.CORE_PROPERTIES_PART, part.getContentType()); } if (part.getPartName().toString().equals("/word/document.xml")) { - assertTrue("Expected one of " + XWPFRelation.MACRO_DOCUMENT + ", " + XWPFRelation.DOCUMENT + ", " + XWPFRelation.TEMPLATE + + assertTrue("Expected one of " + XWPFRelation.MACRO_DOCUMENT + ", " + XWPFRelation.DOCUMENT + ", " + XWPFRelation.TEMPLATE + ", but had " + part.getContentType(), XWPFRelation.DOCUMENT.getContentType().equals(part.getContentType()) || XWPFRelation.MACRO_DOCUMENT.getContentType().equals(part.getContentType()) || @@ -54,9 +54,9 @@ public class OPCFileHandler extends AbstractFileHandler { } } } - + @Override - public void handleExtracting(File file) throws Exception { + public void handleExtracting(File file) { // text-extraction is not possible currently for these types of files } @@ -68,7 +68,7 @@ public class OPCFileHandler extends AbstractFileHandler { try (InputStream stream = new PushbackInputStream(new FileInputStream(file), 100000)) { handleFile(stream, file.getPath()); } - + handleExtracting(file); } } diff --git a/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java b/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java index fa4d038682..78515f450a 100644 --- a/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java +++ b/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java @@ -52,9 +52,7 @@ public class XSLFFileHandler extends SlideShowHandler { // additionally try the other getText() methods - - //noinspection rawtypes - try (SlideShowExtractor extractor = (SlideShowExtractor) ExtractorFactory.createExtractor(file)) { + try (SlideShowExtractor extractor = (SlideShowExtractor) ExtractorFactory.createExtractor(file)) { assertNotNull(extractor); extractor.setSlidesByDefault(true); extractor.setNotesByDefault(true); @@ -81,4 +79,4 @@ public class XSLFFileHandler extends SlideShowHandler { handleExtracting(file); } -} \ No newline at end of file +} diff --git a/src/ooxml/java/org/apache/poi/ooxml/POIXMLRelation.java b/src/ooxml/java/org/apache/poi/ooxml/POIXMLRelation.java index e44a8442fd..ca08b55427 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/POIXMLRelation.java +++ b/src/ooxml/java/org/apache/poi/ooxml/POIXMLRelation.java @@ -56,17 +56,17 @@ public abstract class POIXMLRelation { /** * Describes the content stored in a part. */ - private String _type; + private final String _type; /** * The kind of connection between a source part and a target part in a package. */ - private String _relation; + private final String _relation; /** * The path component of a pack URI. */ - private String _defaultName; + private final String _defaultName; /** * Constructors or factory method to construct instances of this relationship diff --git a/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLDocument.java b/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLDocument.java index aec4e432bf..20d8834845 100644 --- a/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLDocument.java +++ b/src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLDocument.java @@ -37,7 +37,6 @@ import java.util.List; import org.apache.poi.POIDataSamples; import org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart; import org.apache.poi.ooxml.util.PackageHelper; -import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackagePart; @@ -87,7 +86,7 @@ public final class TestPOIXMLDocument { } } - private static void traverse(POIXMLDocument doc) throws IOException{ + private static void traverse(POIXMLDocument doc) { HashMap context = new HashMap<>(); for (RelationPart p : doc.getRelationParts()){ traverse(p, context); @@ -97,7 +96,7 @@ public final class TestPOIXMLDocument { /** * Recursively traverse a OOXML document and assert that same logical parts have the same physical instances */ - private static void traverse(RelationPart rp, HashMap context) throws IOException{ + private static void traverse(RelationPart rp, HashMap context) { POIXMLDocumentPart dp = rp.getDocumentPart(); assertEquals(rp.getRelationship().getTargetURI().toString(), dp.getPackagePart().getPartName().getName()); @@ -255,7 +254,7 @@ public final class TestPOIXMLDocument { } @Test - public void testCommitNullPart() throws IOException, InvalidFormatException { + public void testCommitNullPart() throws IOException { POIXMLDocumentPart part = new POIXMLDocumentPart(); part.prepareForCommit(); part.commit(); @@ -311,6 +310,7 @@ public final class TestPOIXMLDocument { try (InputStream is = pds.openResourceAsStream("bug62513.pptx"); XMLSlideShow ppt = new XMLSlideShow(is)) { POIXMLDocumentPart doc = ppt.getSlides().get(12).getRelationById("rId3"); + assertNotNull(doc); assertEquals(POIXMLDocumentPart.class, doc.getClass()); } } @@ -320,19 +320,17 @@ public final class TestPOIXMLDocument { // the schema type loader is cached per thread in POIXMLTypeLoader. // So create a new Thread and change the context class loader (which would normally be used) // to not contain the OOXML classes - Runnable run = new Runnable() { - public void run() { - InputStream is = POIDataSamples.getSlideShowInstance().openResourceAsStream("table_test.pptx"); - XMLSlideShow ppt = null; - try { - ppt = new XMLSlideShow(is); - ppt.getSlides().get(0).getShapes(); - } catch (IOException e) { - fail("failed to load XMLSlideShow"); - } finally { - IOUtils.closeQuietly(ppt); - IOUtils.closeQuietly(is); - } + Runnable run = () -> { + InputStream is = POIDataSamples.getSlideShowInstance().openResourceAsStream("table_test.pptx"); + XMLSlideShow ppt = null; + try { + ppt = new XMLSlideShow(is); + ppt.getSlides().get(0).getShapes(); + } catch (IOException e) { + fail("failed to load XMLSlideShow"); + } finally { + IOUtils.closeQuietly(ppt); + IOUtils.closeQuietly(is); } }; @@ -348,15 +346,15 @@ public final class TestPOIXMLDocument { ta[i].setUncaughtExceptionHandler(uh); ta[i].start(); } - for (int i=0; i