Browse Source

Bug 64450: Allow to parse a file where the relationship-id is an empty string

Also improve exception reporting by including more information and not
"hiding" the actual exception-cause in a log-statement.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1885056 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_5_0_0
Dominik Stadler 3 years ago
parent
commit
622574f5f4

+ 4
- 4
src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java View File

@@ -194,7 +194,8 @@ public final class PackageRelationshipCollection implements
*/
public void addRelationship(PackageRelationship relPart) {
if (relPart == null || relPart.getId() == null || relPart.getId().isEmpty()) {
throw new IllegalArgumentException("invalid relationship part/id");
throw new IllegalArgumentException("invalid relationship part/id: " +
(relPart == null ? "<null>" : relPart.getId()) + " for relationship: " + relPart);
}
relationshipsByID.put(relPart.getId(), relPart);
relationshipsByType.put(relPart.getRelationshipType(), relPart);
@@ -216,7 +217,7 @@ public final class PackageRelationshipCollection implements
*/
public PackageRelationship addRelationship(URI targetUri,
TargetMode targetMode, String relationshipType, String id) {
if (id == null) {
if (id == null || id.length() == 0) {
// Generate a unique ID is id parameter is null.
if (nextRelationshipId == -1) {
nextRelationshipId = size() + 1;
@@ -354,8 +355,7 @@ public final class PackageRelationshipCollection implements
addRelationship(target, targetMode, type, id);
}
} catch (Exception e) {
logger.log(POILogger.ERROR, e);
throw new InvalidFormatException(e.getMessage());
throw new InvalidFormatException("Failed to parse relationships", e);
}
}


+ 7
- 0
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java View File

@@ -3660,4 +3660,11 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
assertEquals(1, sheet.getDataValidations().size());
}
}

@Test
public void test64450() throws IOException {
try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("64450.xlsx")) {
assertNotNull(wb);
}
}
}

BIN
test-data/spreadsheet/64450.xlsx View File


Loading…
Cancel
Save