Skip to content

Commit

Permalink
Less: eliminate a couple of source.lines() calls
Browse files Browse the repository at this point in the history
Not all Source implementations implement lines() method causing NPE in less.
  • Loading branch information
mattirn committed Dec 9, 2022
1 parent 239d6e0 commit ade7806
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions builtins/src/main/java/org/jline/builtins/Less.java
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ private void moveToPreviousMatch(boolean spanFiles) throws IOException {
String newSource = sources.get(--sourceIdx).getName();
try {
openSource();
firstLineToDisplay = (int)(long)sources.get(sourceIdx).lines();
moveTo(Integer.MAX_VALUE);
moveToPreviousMatch(true);
} catch (FileNotFoundException exp) {
ssp.restore(newSource);
Expand Down Expand Up @@ -1166,12 +1166,9 @@ void moveForward(int lines) throws IOException {
display.clear();
}
if (lines == Integer.MAX_VALUE) {
Long allLines = sources.get(sourceIdx).lines();
if (allLines != null) {
firstLineToDisplay = (int)(long)allLines;
for (int l = 0; l < height - 1; l++) {
firstLineToDisplay = prevLine2display(firstLineToDisplay, dpCompiled).getU();
}
moveTo(Integer.MAX_VALUE);
for (int l = 0; l < height - 1; l++) {
firstLineToDisplay = prevLine2display(firstLineToDisplay, dpCompiled).getU();
}
}
while (--lines >= 0) {
Expand Down

0 comments on commit ade7806

Please sign in to comment.