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

DetectorRepositoryImpl.findByUuid() assumes at least one result #609

Open
williewheeler opened this issue Oct 29, 2019 · 1 comment
Open
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@williewheeler
Copy link
Contributor

In the following code

    @Override
    public DetectorDocument findByUuid(String uuid) {
        val queryBuilder = QueryBuilders.termQuery("uuid", uuid);
        val searchSourceBuilder = elasticsearchUtil.getSourceBuilder(queryBuilder).size(DEFAULT_ES_RESULTS_SIZE);
        val searchRequest = elasticsearchUtil.getSearchRequest(searchSourceBuilder, DETECTOR_INDEX, DETECTOR_DOC_TYPE);
        return getDetectorsFromElasticSearch(searchRequest).get(0);
    }

the last line assumes that there will be at least one detector in the search results, which need not be the case. And we are generating a stack trace over it:

Oct 29, 2019 3:02:02 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IndexOutOfBoundsException: Index: 0, Size: 0] with root cause
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
	at java.util.ArrayList.rangeCheck(ArrayList.java:657)
	at java.util.ArrayList.get(ArrayList.java:433)
	at com.expedia.adaptivealerting.modelservice.repo.impl.DetectorRepositoryImpl.findByUuid(DetectorRepositoryImpl.java:144)
	at com.expedia.adaptivealerting.modelservice.web.DetectorController.findByUuid(DetectorController.java:55)
	at sun.reflect.GeneratedMethodAccessor82.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)

[snip]

Instead this method should handle a missing detector gracefully -- probably by throwing some kind of "not found" exception.

@williewheeler williewheeler added bug Something isn't working good first issue Good for newcomers labels Oct 29, 2019
@vvishwakarma-hc
Copy link

I'm picking up this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants