浏览代码

try to use checked exceptions where APIs already support them

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1904063 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_5_2_4
PJ Fanning 1年前
父节点
当前提交
be9d333493

+ 1
- 0
poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLDocumentPart.java 查看文件

@@ -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) {

+ 8
- 3
poi-ooxml/src/main/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java 查看文件

@@ -164,11 +164,16 @@ public final class POIXMLExtractorFactory implements ExtractorProvider {
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 POIXMLExtractorFactory implements ExtractorProvider {
}

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 POIXMLExtractorFactory implements ExtractorProvider {
fs.close();
}
}
} catch (IOException | RuntimeException e) {
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOException(e);

+ 2
- 2
poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java 查看文件

@@ -136,8 +136,8 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
/**
* 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) {

+ 1
- 1
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFFontInfo.java 查看文件

@@ -212,7 +212,7 @@ public class XSLFFontInfo implements FontInfo {
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);

+ 2
- 2
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java 查看文件

@@ -192,7 +192,7 @@ public class XSLFSlideShow extends POIXMLDocument {
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 POIXMLDocument {
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 {

+ 1
- 0
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java 查看文件

@@ -58,6 +58,7 @@ public class XSSFHyperlink implements Hyperlink, Duplicatable {
*
* @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;

+ 2
- 2
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java 查看文件

@@ -581,10 +581,10 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
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()) {

+ 1
- 1
poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java 查看文件

@@ -91,7 +91,7 @@ public class XWPFStyles extends POIXMLDocumentPart {
@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);

正在加载...
取消
保存