jpountz commented on a change in pull request #769: LUCENE-8905: Better Error 
Handling For Illegal Arguments
URL: https://github.com/apache/lucene-solr/pull/769#discussion_r321139330
 
 

 ##########
 File path: lucene/core/src/java/org/apache/lucene/search/TopDocsCollector.java
 ##########
 @@ -136,14 +136,20 @@ public TopDocs topDocs(int start, int howMany) {
     // pq.size() or totalHits.
     int size = topDocsSize();
 
-    // Don't bother to throw an exception, just return an empty TopDocs in case
-    // the parameters are invalid or out of range.
-    // TODO: shouldn't we throw IAE if apps give bad params here so they dont
-    // have sneaky silent bugs?
-    if (start < 0 || start >= size || howMany <= 0) {
+
+    if (start < 0 || start > howMany) {
+      throw new IllegalArgumentException("Expected value of starting position 
is between 0 and " + size +
+          ", got " + howMany);
+    }
+
+    if (start >= size) {
       return newTopDocs(null, start);
     }
 
+    if (howMany <= 0) {
+      throw new IllegalArgumentException("Number of hits requested must be 
greater than 0 but value was " + howMany);
+    }
 
 Review comment:
   can you move this up? We should validate input parameters before we do 
anything else?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to