Skip to content

Commit d5b3a84

Browse files
committed
SONARJAVA-1588 Log file causing SOError
1 parent f60948a commit d5b3a84

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

java-frontend/src/main/java/org/sonar/java/ast/JavaAstScanner.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ private void simpleScan(File file) {
9191
} catch (Exception e) {
9292
checkInterrrupted(e);
9393
throw new AnalysisException(getAnalyisExceptionMessage(file), e);
94+
} catch (StackOverflowError error) {
95+
LOG.error("A stack overflow error occured while analyzing file: " + file.getAbsolutePath());
96+
throw error;
9497
}
9598
}
9699

java-frontend/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,25 @@ public void should_propagate_visitor_exception_when_no_parse_error() {
161161
scanner.scan(ImmutableList.of(new File("src/test/resources/AstScannerNoParseError.txt")));
162162
}
163163

164+
@Test
165+
public void should_propagate_SOError() {
166+
thrown.expect(StackOverflowError.class);
167+
JavaAstScanner scanner = defaultJavaAstScanner();
168+
scanner.setVisitorBridge(new VisitorsBridge(new CheckThrowingSOError()));
169+
scanner.scan(ImmutableList.of(new File("src/test/resources/AstScannerNoParseError.txt")));
170+
}
171+
164172
private static JavaAstScanner defaultJavaAstScanner() {
165173
return new JavaAstScanner(new ActionParser<Tree>(Charsets.UTF_8, FakeLexer.builder(), FakeGrammar.class, new FakeTreeFactory(), new JavaNodeBuilder(), FakeLexer.ROOT));
166174
}
167175

176+
private static class CheckThrowingSOError implements JavaFileScanner {
177+
178+
@Override
179+
public void scanFile(JavaFileScannerContext context) {
180+
throw new StackOverflowError();
181+
}
182+
}
168183
private static class CheckThrowingException implements JavaFileScanner {
169184

170185
private final RuntimeException exception;

0 commit comments

Comments
 (0)