mirror of
https://github.com/google/nomulus.git
synced 2025-07-22 18:55:58 +02:00
Fix copy causing premature hash calculation (#1189)
* Fix copy causing premature hash calculation The creation of a builder to set the DomainContent repo id in DomainHistory triggers an equality check which causes the hash code of an associated transfer data object to be calculated prematurely, before the Ofy keys are reconstituted. Replace this with a simple setter, which is acceptible in this case because the object is being loaded and is considered to be not fully constructed yet. * Do setRepoId() in Contact and Host history Not essential for these as far as we know, but it's safer and more consistent. * Fixed typos
This commit is contained in:
parent
2017930a8f
commit
d7f7568761
5 changed files with 22 additions and 7 deletions
|
@ -155,9 +155,16 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable {
|
|||
return repoId;
|
||||
}
|
||||
|
||||
/** This method exists solely to satisfy Hibernate. Use {@link Builder} instead. */
|
||||
@SuppressWarnings("UnusedMethod")
|
||||
private void setRepoId(String repoId) {
|
||||
/**
|
||||
* Sets the repository ID.
|
||||
*
|
||||
* <p>This should only be used for restoring the repo id of an object being loaded in a PostLoad
|
||||
* method (effectively, when it is still under construction by Hibernate). In all other cases, the
|
||||
* object should be regarded as immutable and changes should go through a Builder.
|
||||
*
|
||||
* <p>In addition to this special case use, this method must exist to satisfy Hibernate.
|
||||
*/
|
||||
public void setRepoId(String repoId) {
|
||||
this.repoId = repoId;
|
||||
}
|
||||
|
||||
|
|
|
@ -115,7 +115,10 @@ public class ContactHistory extends HistoryEntry implements SqlEntity {
|
|||
contactBase = null;
|
||||
}
|
||||
if (contactBase != null && contactBase.getRepoId() == null) {
|
||||
contactBase = contactBase.asBuilder().setRepoId(parent.getName()).build();
|
||||
// contactBase hasn't been fully constructed yet, so it's ok to go in and mutate it. Though
|
||||
// the use of the Builder is not necessarily problematic in this case, this is still safer as
|
||||
// the Builder can do things like comparisons that compute the hash code.
|
||||
contactBase.setRepoId(parent.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -258,7 +258,10 @@ public class DomainHistory extends HistoryEntry implements SqlEntity {
|
|||
domainContent = null;
|
||||
} else {
|
||||
if (domainContent.getRepoId() == null) {
|
||||
domainContent = domainContent.asBuilder().setRepoId(parent.getName()).build();
|
||||
// domainContent still hasn't been fully constructed yet, so it's ok to go in and mutate
|
||||
// it. In fact, we have to because going through the builder causes the hash codes of
|
||||
// contained objects to be calculated prematurely.
|
||||
domainContent.setRepoId(parent.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,7 +116,10 @@ public class HostHistory extends HistoryEntry implements SqlEntity {
|
|||
hostBase = null;
|
||||
}
|
||||
if (hostBase != null && hostBase.getRepoId() == null) {
|
||||
hostBase = hostBase.asBuilder().setRepoId(parent.getName()).build();
|
||||
// hostBase hasn't been fully constructed yet, so it's ok to go in and mutate it. Though the
|
||||
// use of the Builder is not necessarily problematic in this case, this is still safer as the
|
||||
// Builder can do things like comparisons that compute the hash code.
|
||||
hostBase.setRepoId(parent.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -164,7 +164,6 @@ public class DomainTransferData extends TransferData<DomainTransferData.Builder>
|
|||
serverApproveEntities = null;
|
||||
postLoad();
|
||||
}
|
||||
hashCode = null; // reset the hash code since we may have changed the entities
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue