You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2022/09/14 09:18:58 UTC

svn commit: r1904063 - in /poi/trunk/poi-ooxml/src/main/java/org/apache/poi: ooxml/ ooxml/extractor/ openxml4j/opc/ xslf/usermodel/ xssf/usermodel/ xwpf/usermodel/

Author: fanningpj
Date: Wed Sep 14 09:18:58 2022
New Revision: 1904063

URL: http://svn.apache.org/viewvc?rev=1904063&view=rev
Log:
try to use checked exceptions where APIs already support them

Modified:
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFFontInfo.java
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java?rev=1904063&r1=1904062&r2=1904063&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java Wed Sep 14 09:18:58 2022
@@ -532,6 +532,7 @@ public class POIXMLDocumentPart {
      * @param descriptor The relationship type to find the part number for
      * @param minIdx     The minimum free index to assign, use -1 for any
      * @return The next free part number, or -1 if none available
+     * @throws POIXMLException if the format is invalid
      */
     @Internal
     public final int getNextPartNumber(POIXMLRelation descriptor, int minIdx) {

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java?rev=1904063&r1=1904062&r2=1904063&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java Wed Sep 14 09:18:58 2022
@@ -164,11 +164,16 @@ public final class POIXMLExtractorFactor
             return ex;
         } catch (InvalidFormatException e) {
             throw new IOException(e);
-        } catch (RuntimeException | IOException e) {
+        } catch (IOException e) {
             if (pkg != null) {
                 pkg.revert();
             }
             throw e;
+        } catch (RuntimeException e) {
+            if (pkg != null) {
+                pkg.revert();
+            }
+            throw new IOException(e);
         }
     }
 
@@ -245,7 +250,7 @@ public final class POIXMLExtractorFactor
             }
 
             return null;
-        } catch (Error | RuntimeException | XmlException | OpenXML4JException e) { // NOSONAR
+        } catch (RuntimeException | XmlException | OpenXML4JException e) { // NOSONAR
             throw new IOException(e);
         }
         // we used to close (revert()) the package here, but this is the callers responsibility
@@ -282,7 +287,7 @@ public final class POIXMLExtractorFactor
                         fs.close();
                     }
                 }
-            } catch (IOException | RuntimeException e) {
+            } catch (IOException e) {
                 throw e;
             } catch (Exception e) {
                 throw new IOException(e);

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java?rev=1904063&r1=1904062&r2=1904063&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java Wed Sep 14 09:18:58 2022
@@ -136,8 +136,8 @@ public abstract class OPCPackage impleme
     /**
      * Constructor.
      *
-     * @param access
-     *            Package access.
+     * @param access Package access.
+     * @throws OpenXML4JRuntimeException if there are issues creating properties part
      */
     OPCPackage(PackageAccess access) {
         if (getClass() != ZipPackage.class) {

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFFontInfo.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFFontInfo.java?rev=1904063&r1=1904062&r2=1904063&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFFontInfo.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFFontInfo.java Wed Sep 14 09:18:58 2022
@@ -212,7 +212,7 @@ public class XSLFFontInfo implements Fon
                 try {
                     fntDataIdx = ppt.getPackage().getUnusedPartIndex(fntRel.getDefaultFileName());
                 } catch (InvalidFormatException e) {
-                    throw new IllegalStateException(e);
+                    throw new IOException(e);
                 }
 
                 POIXMLDocumentPart.RelationPart rp = ppt.createRelationship(fntRel, XSLFFactory.getInstance(), fntDataIdx, false);

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java?rev=1904063&r1=1904062&r2=1904063&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java Wed Sep 14 09:18:58 2022
@@ -192,7 +192,7 @@ public class XSLFSlideShow extends POIXM
         try {
             notes = slidePart.getRelationshipsByType(XSLFRelation.NOTES.getRelation());
         } catch(InvalidFormatException e) {
-            throw new IllegalStateException(e);
+            throw new IOException(e);
         }
 
         if(notes.isEmpty()) {
@@ -200,7 +200,7 @@ public class XSLFSlideShow extends POIXM
             return null;
         }
         if(notes.size() > 1) {
-            throw new IllegalStateException("Expecting 0 or 1 notes for a slide, but found " + notes.size());
+            throw new IOException("Expecting 0 or 1 notes for a slide, but found " + notes.size());
         }
 
         try {

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java?rev=1904063&r1=1904062&r2=1904063&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java Wed Sep 14 09:18:58 2022
@@ -58,6 +58,7 @@ public class XSSFHyperlink implements Hy
      *
      * @param ctHyperlink the xml bean containing xml properties
      * @param hyperlinkRel the relationship in the underlying OPC package which stores the actual link's address
+     * @throws IllegalStateException if ctHyperlink Id is null
      */
     protected XSSFHyperlink(CTHyperlink ctHyperlink, PackageRelationship hyperlinkRel) {
         _ctHyperlink = ctHyperlink;

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java?rev=1904063&r1=1904062&r2=1904063&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java Wed Sep 14 09:18:58 2022
@@ -581,10 +581,10 @@ public class XWPFDocument extends POIXML
         try {
             parts = getRelatedByType(XWPFRelation.STYLES.getRelation());
         } catch (InvalidFormatException e) {
-            throw new IllegalStateException(e);
+            throw new IOException(e);
         }
         if (parts.length != 1) {
-            throw new IllegalStateException("Expecting one Styles document part, but found " + parts.length);
+            throw new IOException("Expecting one Styles document part, but found " + parts.length);
         }
 
         try (InputStream stream = parts[0].getInputStream()) {

Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java?rev=1904063&r1=1904062&r2=1904063&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java Wed Sep 14 09:18:58 2022
@@ -91,7 +91,7 @@ public class XWPFStyles extends POIXMLDo
     @Override
     protected void commit() throws IOException {
         if (ctStyles == null) {
-            throw new IllegalStateException("Unable to write out styles that were never read in!");
+            throw new IOException("Unable to write out styles that were never read in!");
         }
 
         XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);



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