mirror of https://github.com/apache/lucene.git
Avoid NPEx if the end of the stream has been reached without reading any characters (#12611)
e.g. by user responding with ^D ``` Press (n)ext page, (q)uit or enter number to jump to a page. Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.length()" because "line" is null at org.apache.lucene.demo.SearchFiles.doPagingSearch(SearchFiles.java:244) at org.apache.lucene.demo.SearchFiles.main(SearchFiles.java:152) ``` ``` Press (p)revious page, (n)ext page, (q)uit or enter number to jump to a page. n Only results 1 - 50 of 104 total matching documents collected. Collect more (y/n) ? Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.length()" because "line" is null at org.apache.lucene.demo.SearchFiles.doPagingSearch(SearchFiles.java:198) at org.apache.lucene.demo.SearchFiles.main(SearchFiles.java:152) ``` Co-authored-by: Piotrek Żygieło <pzygielo@users.noreply.github.com>
This commit is contained in:
parent
ce3a904465
commit
dfff1e6358
|
@ -195,7 +195,7 @@ public class SearchFiles {
|
|||
+ " total matching documents collected.");
|
||||
System.out.println("Collect more (y/n) ?");
|
||||
String line = in.readLine();
|
||||
if (line.length() == 0 || line.charAt(0) == 'n') {
|
||||
if (line == null || line.length() == 0 || line.charAt(0) == 'n') {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -241,7 +241,7 @@ public class SearchFiles {
|
|||
System.out.println("(q)uit or enter number to jump to a page.");
|
||||
|
||||
String line = in.readLine();
|
||||
if (line.length() == 0 || line.charAt(0) == 'q') {
|
||||
if (line == null || line.length() == 0 || line.charAt(0) == 'q') {
|
||||
quit = true;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue