Skip to content

Commit

Permalink
Properly handle removal of transient fields. Till now it was not poss…
Browse files Browse the repository at this point in the history
…ible to remove them.
  • Loading branch information
romix committed May 22, 2014
1 parent b82531a commit faca949
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/com/esotericsoftware/kryo/serializers/FieldSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,18 @@ public void removeField (String fieldName) {
return;
}
}

for (int i = 0; i < transientFields.length; i++) {
CachedField cachedField = transientFields[i];
if (cachedField.field.getName().equals(fieldName)) {
CachedField[] newFields = new CachedField[transientFields.length - 1];
System.arraycopy(transientFields, 0, newFields, 0, i);
System.arraycopy(transientFields, i + 1, newFields, i, newFields.length - i);
transientFields = newFields;
removedFields.add(cachedField);
return;
}
}
throw new IllegalArgumentException("Field \"" + fieldName + "\" not found on class: " + type.getName());
}

Expand All @@ -583,6 +595,18 @@ public void removeField (CachedField removeField) {
return;
}
}

for (int i = 0; i < transientFields.length; i++) {
CachedField cachedField = transientFields[i];
if (cachedField == removeField) {
CachedField[] newFields = new CachedField[transientFields.length - 1];
System.arraycopy(transientFields, 0, newFields, 0, i);
System.arraycopy(transientFields, i + 1, newFields, i, newFields.length - i);
transientFields = newFields;
removedFields.add(cachedField);
return;
}
}
throw new IllegalArgumentException("Field \"" + removeField + "\" not found on class: " + type.getName());
}

Expand Down

0 comments on commit faca949

Please sign in to comment.