Bug 65084

Summary: A same message is attached to different exceptions
Product: POI Reporter: zhonghao
Component: OPCAssignee: POI Developers List <dev>
Status: NEW ---    
Severity: enhancement    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: All   

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?