Bug 63676 - fixes:poi-ooxml-4.1.0:OPC:The equals (Object obj) method errors in the class org.apache.poi.openxml4j.opc.internal.ContentType and Potential bugs in method equals () and hashCode() of the class org.apache.poi.openxml4j.opc.PackageRelationship
Summary: fixes:poi-ooxml-4.1.0:OPC:The equals (Object obj) method errors in the class ...
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: OPC (show other bugs)
Version: unspecified
Hardware: PC
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-20 15:38 UTC by xiao yuan
Modified: 2019-08-20 15:38 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description xiao yuan 2019-08-20 15:38:29 UTC
Here are my modifications:
in the class org.apache.poi.openxml4j.opc.internal.ContentType:
@Override
public boolean equals(Object obj) {

        return (obj instanceof ContentType) &&(this.toString().equalsIgnoreCase(obj.toString()));

}
-----------------------------------------
Potential bugs in method equals () and hashCode() of the class org.apache.poi.openxml4j.opc.PackageRelationship.I don't know if the following changes are appropriate:
in the class PackageRelationship:
    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof PackageRelationship)) {
            return false;
        }
        PackageRelationship rel = (PackageRelationship) obj;
        return this.relationshipType.equals(rel.relationshipType)
                && (rel.source != null?rel.source.equals(this.source):this.source == null )
                && this.targetMode == rel.targetMode
                && this.targetUri.equals(rel.targetUri);
    }

    @Override
    public int hashCode() {
        return this.relationshipType.hashCode()
                + (this.source == null ? 0 : this.source.hashCode())
                + this.targetMode.hashCode()
                + this.targetUri.hashCode();
    }

and I removed id compared in method equals () and hashCode().I don't think that if there are duplicate relationship types in the *.rels file, ID should not be compared.In addition, add equals() and hashCode() methods to the class org.apache.poi.openxml4j.opc.PackagePart.

@Override
    public int hashCode() {
        return partName.hashCode() + contentType.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        return obj instanceof PackagePart 
               &&this.partName.equals(((PackagePart) obj).partName)
               &&this.contentType.equals(((PackagePart) obj).contentType);
    }