Skip to content

Commit

Permalink
Fix crash during error reporting
Browse files Browse the repository at this point in the history
If ErrorProneScanner.scan(Tree, VisitorState) is called directly, the
TreePath may not have been initialized when it handles a crash.

RELNOTES: N/A
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=118597461
  • Loading branch information
cushon committed Apr 8, 2016
1 parent 5eeebb7 commit 8390411
Showing 1 changed file with 7 additions and 6 deletions.
Expand Up @@ -1037,10 +1037,7 @@ public Void scan(TreePath path, VisitorState state) {
} catch (ErrorProneError e) {
throw e;
} catch (Throwable t) {
throw new ErrorProneError(
t,
(DiagnosticPosition) path.getLeaf(),
state.getPath().getCompilationUnit().getSourceFile());
throw wrapWithPosition(t, path);
}
}

Expand All @@ -1051,11 +1048,15 @@ public Void scan(Tree tree, VisitorState state) {
} catch (ErrorProneError e) {
throw e;
} catch (Throwable t) {
throw new ErrorProneError(
t, (DiagnosticPosition) tree, getCurrentPath().getCompilationUnit().getSourceFile());
throw wrapWithPosition(t, new TreePath(getCurrentPath(), tree));
}
}

static ErrorProneError wrapWithPosition(Throwable t, TreePath path) {
return new ErrorProneError(
t, (DiagnosticPosition) path.getLeaf(), path.getCompilationUnit().getSourceFile());
}

@Override
public Map<String, SeverityLevel> severityMap() {
return severities;
Expand Down

0 comments on commit 8390411

Please sign in to comment.