@@ -87,7 +87,15 @@ private static NewIssueLocation newLocation(InputFile inputFile, NewIssue issue,
8787 if (location .startLineOffset () == IssueLocation .UNDEFINED_OFFSET ) {
8888 range = inputFile .selectLine (location .startLine ());
8989 } else {
90- range = inputFile .newRange (location .startLine (), location .startLineOffset (), location .endLine (), location .endLineOffset ());
90+ try {
91+ range = inputFile .newRange (location .startLine (), location .startLineOffset (), location .endLine (), location .endLineOffset ());
92+ } catch (IllegalArgumentException e ) {
93+ try {
94+ range = inputFile .selectLine (location .startLine ());
95+ } catch (IllegalArgumentException e2 ) {
96+ range = inputFile .selectLine (1 );
97+ }
98+ }
9199 }
92100 newLocation .at (range );
93101 }
@@ -133,13 +141,14 @@ private void scanFile(InputFile inputFile) {
133141
134142 } catch (RecognitionException e ) {
135143 visitorContext = new OpenApiVisitorContext (openApiFile , e );
136- LOG .error ("Unable to parse file: " + inputFile .filename () + "\" \n " + e .getMessage ());
144+ LOG .error ("Unable to parse file in recognition : " + inputFile .filename () + "\" \n " + e .getMessage ());
137145 dumpException (e , inputFile );
138146
139147 } catch (IOException ex ) {
140148 RecognitionException re = new RecognitionException (0 , ex .getMessage ());
141149 visitorContext = new OpenApiVisitorContext (openApiFile , re );
142- LOG .error ("Unable to parse file: " + inputFile .filename () + "\" \n " + ex .getMessage ());
150+ LOG .error ("Unable to parse file in i/o: " + inputFile .filename () + "\" \n " + ex .getMessage ());
151+ dumpException (re , inputFile );
143152 }
144153
145154 for (OpenApiCheck check : checks .all ()) {
@@ -172,11 +181,11 @@ private String getContent(InputFile inputFile) throws IOException {
172181
173182 private void dumpException (RecognitionException e , InputFile inputFile ) {
174183 int line = e .getLine ();
175- if (line == 0 ) {
184+ if (line == 0 || line > inputFile . lines () ) {
176185 line = 1 ;
177186 }
178187 int column = 0 ;
179- if (e instanceof ValidationException ) {
188+ if (line != 1 && ( e instanceof ValidationException ) ) {
180189 column = ((ValidationException ) e ).getNode ().getToken ().getColumn ();
181190 for (ValidationException cause : ((ValidationException ) e ).getCauses ()) {
182191 dumpException (cause , inputFile );
0 commit comments