Skip to content

Commit

Permalink
Avoid casting to generate SimplifiedIntervalList (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
QubitPi authored Apr 23, 2018
1 parent ecb4253 commit bd15986
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ pull request if there was one.

### Changed:


- [Avoid casting to generate SimplifiedIntervalList](https://github.com/yahoo/fili/pull/677)
* Some downstream projects generated partial intervals as `ArrayList`, which cannot be cased to
`SimplifiedIntervalList` in places like `getVolatileIntervalsWithDefault`. The result is a casting exception which
crashes downstream applications. Casting is replaced with a explicit `SimplifiedIntervalList` object creation.

### Deprecated:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import com.yahoo.bard.webservice.web.responseprocessors.ResponseContext;
import com.yahoo.bard.webservice.web.responseprocessors.ResponseProcessor;

import org.joda.time.Interval;

import java.io.Serializable;
import java.util.Collection;
import java.util.Map;

import javax.validation.constraints.NotNull;
Expand Down Expand Up @@ -85,9 +88,11 @@ public boolean handleRequest(
* @return the volatile intervals from the request or an empty list
*/
public static SimplifiedIntervalList getVolatileIntervalsWithDefault(Map<String, Serializable> context) {
return (SimplifiedIntervalList) context.computeIfAbsent(
VOLATILE_INTERVALS_CONTEXT_KEY.getName(),
(ignored) -> new SimplifiedIntervalList()
return new SimplifiedIntervalList(
(Collection<Interval>) context.computeIfAbsent(
VOLATILE_INTERVALS_CONTEXT_KEY.getName(),
(ignored) -> new SimplifiedIntervalList()
)
);
}
}

0 comments on commit bd15986

Please sign in to comment.