handle nulls correctly

This commit is contained in:
Athou
2014-11-22 11:53:46 +01:00
parent cbc792d406
commit d1be331f99
2 changed files with 11 additions and 4 deletions

View File

@@ -82,10 +82,11 @@ public class FeedEntryFilteringService {
}
JexlContext context = new MapContext();
context.set("title", Jsoup.parse(entry.getContent().getTitle()).text().toLowerCase());
context.set("author", entry.getContent().getAuthor().toLowerCase());
context.set("content", Jsoup.parse(entry.getContent().getContent()).text().toLowerCase());
context.set("url", entry.getUrl().toLowerCase());
context.set("title", entry.getContent().getTitle() == null ? "" : Jsoup.parse(entry.getContent().getTitle()).text().toLowerCase());
context.set("author", entry.getContent().getAuthor() == null ? "" : entry.getContent().getAuthor().toLowerCase());
context.set("content", entry.getContent().getContent() == null ? "" : Jsoup.parse(entry.getContent().getContent()).text()
.toLowerCase());
context.set("url", entry.getUrl() == null ? "" : entry.getUrl().toLowerCase());
Callable<Object> callable = script.callable(context);
Future<Object> future = executor.submit(callable);

View File

@@ -65,4 +65,10 @@ public class FeedEntryFilteringServiceTest {
service.filterMatchesEntry("while(true) {}", entry);
}
@Test
public void handlesNullCorrectly() throws FeedEntryFilterException {
entry.setContent(new FeedEntryContent());
service.filterMatchesEntry("author eq 'athou'", entry);
}
}