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
This commit is contained in:
Dominik Stadler 2021-01-03 11:49:51 +00:00
parent 400a3ae631
commit 622574f5f4
3 changed files with 11 additions and 4 deletions

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);
}
}

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);
}
}
}

Binary file not shown.