Skip to content

Commit

Permalink
crash-proof PropertyValueIterable in case of unintentional use of val…
Browse files Browse the repository at this point in the history
…ues of different types for a single property
  • Loading branch information
penemue committed Oct 2, 2019
1 parent 48b5d93 commit 7d77dda
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,21 @@ public final class PropertyValueIterable extends PropertyRangeOrValueIterableBas

@NotNull
private final Comparable value;
@NotNull
private final Class<? extends Comparable> valueClass;

static {
registerType(getType(), new EntityIterableInstantiator() {
@Override
public EntityIterableBase instantiate(PersistentStoreTransaction txn, PersistentEntityStoreImpl store, Object[] parameters) {
try {
return new PropertyValueIterable(txn,
Integer.valueOf((String) parameters[0]), Integer.valueOf((String) parameters[1]),
Long.parseLong((String) parameters[2]));
Integer.valueOf((String) parameters[0]), Integer.valueOf((String) parameters[1]),
Long.parseLong((String) parameters[2]));
} catch (NumberFormatException e) {
return new PropertyValueIterable(txn,
Integer.valueOf((String) parameters[0]), Integer.valueOf((String) parameters[1]),
(Comparable) parameters[2]);
Integer.valueOf((String) parameters[0]), Integer.valueOf((String) parameters[1]),
(Comparable) parameters[2]);
}
}
});
Expand All @@ -58,6 +60,7 @@ public PropertyValueIterable(@NotNull final PersistentStoreTransaction txn,
@NotNull final Comparable value) {
super(txn, entityTypeId, propertyId);
this.value = PropertyTypes.toLowerCase(value);
valueClass = value.getClass();
}

@Override
Expand Down Expand Up @@ -141,6 +144,7 @@ private boolean isValueMatched(Comparable value) {
if (value instanceof ComparableSet) {
return ((ComparableSet) value).containsItem(PropertyValueIterable.this.value);
}
if (value.getClass() != valueClass) return false;
value = PropertyTypes.toLowerCase(value);
return value.compareTo(PropertyValueIterable.this.value) == 0;
}
Expand Down

0 comments on commit 7d77dda

Please sign in to comment.