Skip to content

Commit bf7db42

Browse files
Hotfix 1.0.4, enchance issue location to be more fault tolerant
1 parent c5ae3d5 commit bf7db42

File tree

7 files changed

+20
-11
lines changed

7 files changed

+20
-11
lines changed

its/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.apiaddicts.apitools.dosonarapi</groupId>
77
<artifactId>dosonarapi</artifactId>
8-
<version>1.0.3</version>
8+
<version>1.0.4</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>

openapi-checks/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.apiaddicts.apitools.dosonarapi</groupId>
77
<artifactId>dosonarapi</artifactId>
8-
<version>1.0.3</version>
8+
<version>1.0.4</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

openapi-front-end/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.apiaddicts.apitools.dosonarapi</groupId>
77
<artifactId>dosonarapi</artifactId>
8-
<version>1.0.3</version>
8+
<version>1.0.4</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

openapi-test-tools/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.apiaddicts.apitools.dosonarapi</groupId>
77
<artifactId>dosonarapi</artifactId>
8-
<version>1.0.3</version>
8+
<version>1.0.4</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<groupId>org.apiaddicts.apitools.dosonarapi</groupId>
1111
<artifactId>dosonarapi</artifactId>
12-
<version>1.0.3</version>
12+
<version>1.0.4</version>
1313
<packaging>pom</packaging>
1414

1515
<name>SonarOpenAPI</name>

sonar-openapi-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.apiaddicts.apitools.dosonarapi</groupId>
77
<artifactId>dosonarapi</artifactId>
8-
<version>1.0.3</version>
8+
<version>1.0.4</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

sonar-openapi-plugin/src/main/java/org/apiaddicts/apitools/dosonarapi/plugin/OpenApiAnalyzer.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)