Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid casting to generate SimplifiedIntervalList #678

Merged
merged 3 commits into from
Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
)
);
}
}