Skip to content

Commit

Permalink
Fix line/col numbers in TokenMgrError
Browse files Browse the repository at this point in the history
Ref pmd#4635

Col number of zero may happen when the error is reported
on a newline. In the rest of PMD a newline is considered
to sit at the last index of the previous line. So the index
is now the first character of the next line, which is slightly
wrong but that doesn't matter much.
  • Loading branch information
oowekyala committed Jul 26, 2023
1 parent 3e2de67 commit 310f68a
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package net.sourceforge.pmd.lang.ast;

import static java.lang.Math.max;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

Expand Down Expand Up @@ -31,8 +33,8 @@ public final class TokenMgrError extends FileAnalysisException {
*/
public TokenMgrError(int line, int column, @Nullable FileId filename, String message, @Nullable Throwable cause) {
super(message, cause);
this.line = line;
this.column = column;
this.line = max(line, 1);
this.column = max(column, 1);
if (filename != null) {
super.setFileId(filename);
}
Expand All @@ -44,8 +46,8 @@ public TokenMgrError(int line, int column, @Nullable FileId filename, String mes
@InternalApi
public TokenMgrError(boolean eofSeen, String lexStateName, int errorLine, int errorColumn, String errorAfter, char curChar) {
super(makeReason(eofSeen, lexStateName, errorAfter, curChar));
line = errorLine;
column = errorColumn;
line = max(errorLine, 1);
column = max(errorColumn, 1);
}

public int getLine() {
Expand Down

0 comments on commit 310f68a

Please sign in to comment.