diff --git a/src/main/java/com/massivecraft/massivecore/store/Coll.java b/src/main/java/com/massivecraft/massivecore/store/Coll.java index a4cd8656..72d6da46 100644 --- a/src/main/java/com/massivecraft/massivecore/store/Coll.java +++ b/src/main/java/com/massivecraft/massivecore/store/Coll.java @@ -352,8 +352,17 @@ public class Coll implements CollInterface @Override public E detachEntity(Object entity) { + if (entity == null) throw new NullPointerException("entity"); + E e = (E)entity; String id = this.getId(e); + if (id == null) + { + // It seems the entity is already detached. + // In such case just silently return it. + return e; + } + this.detach(e, id); return e; } @@ -361,6 +370,8 @@ public class Coll implements CollInterface @Override public E detachId(Object oid) { + if (oid == null) throw new NullPointerException("oid"); + String id = this.fixId(oid); E e = this.get(id); this.detach(e, id); @@ -369,6 +380,9 @@ public class Coll implements CollInterface private void detach(E entity, String id) { + if (entity == null) throw new NullPointerException("entity"); + if (id == null) throw new NullPointerException("id"); + // PRE this.preDetach(entity, id); @@ -429,6 +443,8 @@ public class Coll implements CollInterface protected synchronized void clearIdentifiedChanges(Object oid) { + if (oid == null) throw new NullPointerException("oid"); + String id = this.fixId(oid); this.localAttachIds.remove(id); this.localDetachIds.remove(id); @@ -445,6 +461,8 @@ public class Coll implements CollInterface protected synchronized void clearSynclog(Object oid) { + if (oid == null) throw new NullPointerException("oid"); + String id = this.fixId(oid); this.lastMtime.remove(id); this.lastRaw.remove(id); @@ -482,7 +500,10 @@ public class Coll implements CollInterface @Override public synchronized E removeAtLocal(Object oid) { + if (oid == null) throw new NullPointerException("oid"); + String id = this.fixId(oid); + this.clearIdentifiedChanges(id); this.clearSynclog(id); @@ -506,6 +527,8 @@ public class Coll implements CollInterface @Override public synchronized void removeAtRemote(Object oid) { + if (oid == null) throw new NullPointerException("oid"); + String id = this.fixId(oid); this.clearIdentifiedChanges(id); @@ -517,6 +540,8 @@ public class Coll implements CollInterface @Override public synchronized void saveToRemote(Object oid) { + if (oid == null) throw new NullPointerException("oid"); + String id = this.fixId(oid); this.clearIdentifiedChanges(id); @@ -545,6 +570,8 @@ public class Coll implements CollInterface @Override public synchronized void loadFromRemote(Object oid) { + if (oid == null) throw new NullPointerException("oid"); + String id = this.fixId(oid); this.clearIdentifiedChanges(id); diff --git a/src/main/java/com/massivecraft/massivecore/store/Entity.java b/src/main/java/com/massivecraft/massivecore/store/Entity.java index f629455b..1db7b894 100644 --- a/src/main/java/com/massivecraft/massivecore/store/Entity.java +++ b/src/main/java/com/massivecraft/massivecore/store/Entity.java @@ -57,10 +57,11 @@ public abstract class Entity> implements Comparable return coll.attach((E) this); } + @SuppressWarnings("unchecked") public E detach() { Coll coll = this.getColl(); - if (coll == null) return null; + if (coll == null) return (E)this; return coll.detachEntity(this); }