Skip to content

Commit

Permalink
Merge pull request #1029 from HubSpot/check-before-iterating
Browse files Browse the repository at this point in the history
check iterator before calling next
  • Loading branch information
boulter authored Mar 14, 2023
2 parents be1d00d + 772de7f commit e4ce11a
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hubspot.jinjava.el;

import java.util.Iterator;
import java.util.Map;
import javax.el.ELContext;
import javax.el.ELException;
Expand All @@ -21,14 +22,17 @@ public Object getValue(ELContext context, Object base, Object property) {
}

if (base instanceof Map && !((Map) base).isEmpty()) {
Class<?> keyClass = ((Map) base).keySet().iterator().next().getClass();
try {
value = ((Map) base).get(TYPE_CONVERTER.convert(property, keyClass));
if (value != null) {
context.setPropertyResolved(true);
Iterator<?> iterator = ((Map) base).keySet().iterator();
if (iterator.hasNext()) {
Class<?> keyClass = iterator.next().getClass();
try {
value = ((Map) base).get(TYPE_CONVERTER.convert(property, keyClass));
if (value != null) {
context.setPropertyResolved(true);
}
} catch (ELException ex) {
value = null;
}
} catch (ELException ex) {
value = null;
}
}

Expand Down

0 comments on commit e4ce11a

Please sign in to comment.