Catch exceptions caused by fetching with invalid indices

This commit is contained in:
Masaki Mori
2015-09-09 11:15:56 +09:00
parent e7daae3912
commit b846605894
2 changed files with 24 additions and 0 deletions
@@ -8,6 +8,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
/**
* A collector that does not use reflection and can be used with GWT.
@@ -58,6 +59,8 @@ public abstract class BasicCollector implements Mustache.Collector
return ((List<?>)ctx).get(Integer.parseInt(name));
} catch (NumberFormatException nfe) {
return Template.NO_FETCHER_FOUND;
} catch (IndexOutOfBoundsException e) {
return Template.NO_FETCHER_FOUND;
}
}
};
@@ -68,6 +71,8 @@ public abstract class BasicCollector implements Mustache.Collector
return ((Object[])ctx)[Integer.parseInt(name)];
} catch (NumberFormatException nfe) {
return Template.NO_FETCHER_FOUND;
} catch (IndexOutOfBoundsException e) {
return Template.NO_FETCHER_FOUND;
}
}
};
@@ -80,6 +85,8 @@ public abstract class BasicCollector implements Mustache.Collector
return iter.next();
} catch (NumberFormatException nfe) {
return Template.NO_FETCHER_FOUND;
} catch (NoSuchElementException e) {
return Template.NO_FETCHER_FOUND;
}
}
};