Skip to content

Commit

Permalink
Handle diagnostics without source
Browse files Browse the repository at this point in the history
In some cases, compiler diagnostics may not have an associated source,
and for testing whether suggested fixes compile these should be treated
as originating from the same compilation unit of the suggested fix.

Fixes #1873

Fixes #2064

COPYBARA_INTEGRATE_REVIEW=#2064 from schlosna:ds/1873-SuggestedFixes-NPE ddd042b
PiperOrigin-RevId: 350812718
  • Loading branch information
schlosna authored and Error Prone Team committed Jan 8, 2021
1 parent be57b1b commit 886ed1c
Showing 1 changed file with 3 additions and 1 deletion.
Expand Up @@ -1309,8 +1309,10 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOExcept
boolean warningInSameCompilationUnit = false;
for (Diagnostic<? extends JavaFileObject> diagnostic : diagnosticListener.getDiagnostics()) {
warningIsError |= diagnostic.getCode().equals("compiler.err.warnings.and.werror");
JavaFileObject diagnosticSource = diagnostic.getSource();
// If the source's origin is unknown, assume that new diagnostics are due to a modification.
boolean diagnosticInSameCompilationUnit =
diagnostic.getSource().toUri().equals(modifiedFileUri);
diagnosticSource == null || diagnosticSource.toUri().equals(modifiedFileUri);
switch (diagnostic.getKind()) {
case ERROR:
++countErrors;
Expand Down

0 comments on commit 886ed1c

Please sign in to comment.