diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/reader/TimelineParserForCompareExpr.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/reader/TimelineParserForCompareExpr.java index 1b020d93f0c..35b24b4492b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/reader/TimelineParserForCompareExpr.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/reader/TimelineParserForCompareExpr.java @@ -282,7 +282,11 @@ public TimelineFilterList parse() throws TimelineParseException { parseValue(expr.substring(kvStartOffset, offset))); } if (filterList == null || filterList.getFilterList().isEmpty()) { - filterList = new TimelineFilterList(currentFilter); + if (currentFilter == null) { + throw new TimelineParseException("Invalid expression provided."); + } else { + filterList = new TimelineFilterList(currentFilter); + } } else if (currentFilter != null) { filterList.addFilter(currentFilter); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/reader/TimelineParserForEqualityExpr.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/reader/TimelineParserForEqualityExpr.java index 74517133c6d..37c057ffd41 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/reader/TimelineParserForEqualityExpr.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/reader/TimelineParserForEqualityExpr.java @@ -325,7 +325,11 @@ public TimelineFilterList parse() throws TimelineParseException { } } if (filterList == null || filterList.getFilterList().isEmpty()) { - filterList = new TimelineFilterList(currentFilter); + if (currentFilter == null) { + throw new TimelineParseException("Invalid expression provided."); + } else { + filterList = new TimelineFilterList(currentFilter); + } } else if (currentFilter != null) { filterList.addFilter(currentFilter); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/TestTimelineReaderWebServicesUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/TestTimelineReaderWebServicesUtils.java index b2837c20c98..f96006df3dd 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/TestTimelineReaderWebServicesUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/TestTimelineReaderWebServicesUtils.java @@ -31,6 +31,7 @@ import org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValueFilter; import org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelineKeyValuesFilter; import org.apache.hadoop.yarn.server.timelineservice.reader.filter.TimelinePrefixFilter; +import org.junit.Assert; import org.junit.Test; import com.google.common.collect.Sets; @@ -520,6 +521,14 @@ public void testInfoFiltersParsing() throws Exception { ); verifyFilterList(expr, TimelineReaderWebServicesUtils. parseKVFilters(expr, false), expectedList); + + expr = "abdeq"; + try { + TimelineReaderWebServicesUtils.parseKVFilters(expr, false); + Assert.fail("Expression valuation should throw exception."); + } catch (TimelineParseException e) { + // expected: do nothing + } } @Test