Skip to content

Commit

Permalink
Add failsafe for CatalogTypes that are DataSerializables.
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Harris-Rouquette <[email protected]>
  • Loading branch information
gabizou committed Mar 17, 2016
1 parent 7e9670d commit b29342e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/main/java/org/spongepowered/api/data/MemoryDataView.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,13 @@ public DataView set(DataQuery path, Object value) {
if (value instanceof DataView) {
checkArgument(value != this, "Cannot set a DataView to itself.");
copyDataView(path, (DataView) value);
} else if (value instanceof CatalogType) {
return set(path, ((CatalogType) value).getId());
} else if (value instanceof DataSerializable) {
}else if (value instanceof DataSerializable) {

This comment has been minimized.

Copy link
@liach

liach Mar 17, 2016

Contributor

spacing

Note: Posted at #1000 (comment)

This comment has been minimized.

Copy link
@gabizou

gabizou Mar 17, 2016

Author Member

That's nice. Maybe actually post on the OCD issue?

This comment has been minimized.

Copy link
@ST-DDT

ST-DDT Mar 17, 2016

Member

Which data would you like to safe in catalog type serializables? Afaik you cannot restore the data at all because data serializables are supposed to be unique.

This comment has been minimized.

Copy link
@gabizou

gabizou Mar 17, 2016

Author Member

catalog type serializables

By definition of being DataSerializable, you guarantee that your data can be deserialized to restore yourself. By definition of CatalogType, you guarantee that you have a unique String id that can link back to yourself through the GameRegistry. Where is it not clear that you have more than enough data to deserialize from to get back the object that implements both CatalogType and DataSerializable?

DataContainer valueContainer = ((DataSerializable) value).toContainer();
checkArgument(!(valueContainer).equals(this), "Cannot insert self-referencing DataSerializable");
copyDataView(path, valueContainer);
} else {
} else if (value instanceof CatalogType) {
return set(path, ((CatalogType) value).getId());
} else {
List<String> parts = path.getParts();
if (parts.size() > 1) {
String subKey = parts.get(0);
Expand Down Expand Up @@ -791,7 +791,10 @@ public <T extends DataSerializable> Optional<T> getSerializable(DataQuery path,
checkNotNull(clazz, "clazz");
DataManager manager = Sponge.getDataManager();
if (clazz.isAssignableFrom(CatalogType.class)) {
return (Optional<T>) getCatalogType(path, ((Class<? extends CatalogType>) clazz));
final Optional<T> catalog = (Optional<T>) getCatalogType(path, ((Class<? extends CatalogType>) clazz));
if (catalog.isPresent()) {
return catalog;
}
}
Optional<DataView> optional = getUnsafeView(path);

Expand Down

0 comments on commit b29342e

Please sign in to comment.