From 7d77dda82c021b3a5343d4de2e1d754333d225b7 Mon Sep 17 00:00:00 2001 From: Vyacheslav Lukianov Date: Wed, 2 Oct 2019 12:47:01 +0300 Subject: [PATCH] crash-proof PropertyValueIterable in case of unintentional use of values of different types for a single property --- .../entitystore/iterate/PropertyValueIterable.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/entity-store/src/main/java/jetbrains/exodus/entitystore/iterate/PropertyValueIterable.java b/entity-store/src/main/java/jetbrains/exodus/entitystore/iterate/PropertyValueIterable.java index 73191a411..609d5899b 100644 --- a/entity-store/src/main/java/jetbrains/exodus/entitystore/iterate/PropertyValueIterable.java +++ b/entity-store/src/main/java/jetbrains/exodus/entitystore/iterate/PropertyValueIterable.java @@ -34,6 +34,8 @@ public final class PropertyValueIterable extends PropertyRangeOrValueIterableBas @NotNull private final Comparable value; + @NotNull + private final Class valueClass; static { registerType(getType(), new EntityIterableInstantiator() { @@ -41,12 +43,12 @@ public final class PropertyValueIterable extends PropertyRangeOrValueIterableBas 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]); } } }); @@ -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 @@ -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; }