Bug 65084 - A same message is attached to different exceptions
Summary: A same message is attached to different exceptions
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: OPC (show other bugs)
Version: unspecified
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-16 07:37 UTC by zhonghao
Modified: 2021-01-23 13:08 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description zhonghao 2021-01-16 07:37:17 UTC
The message is " Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names". It is attached to three different exceptions.

1. OPCPackage#addPackagePart throws InvalidOperationException:

protected PackagePart addPackagePart(PackagePart part) {
  ...
   if (partList.containsKey(part._partName)) {
			if (!partList.get(part._partName).isDeleted()) {
				throw new InvalidOperationException(
						"A part with the name '"
								+ part._partName.getName()
								+ "' already exists : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
			}
			// If the specified partis flagged as deleted, we make it
			// available
			part.setDeleted(false);
			// and delete the old part to replace it thereafeter
			this.partList.remove(part._partName);
		}
}

2. ZipPackage.EntryTriple#register throws InvalidFormatException:
private class EntryTriple implements Comparable<EntryTriple> {
 ...
  if (partList.containsKey(partName)) {
                throw new InvalidFormatException(
                    "A part with the name '"+partName+"' already exist : Packages shall not contain equivalent part names " +
                    "and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
            }
}

3. OPCPackage#createPart throws PartAlreadyExistsException:

PackagePart createPart(PackagePartName partName, String contentType,
			boolean loadRelationships) {
...
if (partList.containsKey(partName)
				&& !partList.get(partName).isDeleted()) {
			throw new PartAlreadyExistsException(
					"A part with the name '" + partName.getName() + "'" +
					" already exists : Packages shall not contain equivalent part names and package" +
					" implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
		}
...
}


It is strange to find the same type of errors is attached to three different exceptions. InvalidOperationException looks better than the other two, as far as the message is concerned. Maybe, the messages themselves shall be revised?