|
24 | 24 | import static com.google.errorprone.bugpatterns.javadoc.Utils.getStartPosition; |
25 | 25 | import static com.google.errorprone.bugpatterns.javadoc.Utils.replace; |
26 | 26 | import static com.google.errorprone.matchers.Description.NO_MATCH; |
| 27 | +import static com.google.errorprone.util.ErrorProneLog.deferredDiagnosticHandler; |
27 | 28 |
|
28 | 29 | import com.google.common.collect.ImmutableSet; |
29 | 30 | import com.google.errorprone.BugPattern; |
|
46 | 47 | import com.sun.tools.javac.api.JavacTrees; |
47 | 48 | import com.sun.tools.javac.tree.DCTree.DCDocComment; |
48 | 49 | import com.sun.tools.javac.tree.DCTree.DCText; |
| 50 | +import com.sun.tools.javac.util.Log; |
49 | 51 | import java.util.regex.Matcher; |
50 | 52 | import java.util.regex.Pattern; |
51 | 53 | import javax.lang.model.element.Element; |
@@ -143,9 +145,20 @@ public Void visitLink(LinkTree linkTree, Void unused) { |
143 | 145 | return super.visitLink(linkTree, null); |
144 | 146 | } |
145 | 147 | String reference = linkTree.getReference().getSignature(); |
146 | | - Element element = |
147 | | - JavacTrees.instance(state.context) |
148 | | - .getElement(new DocTreePath(getCurrentPath(), linkTree.getReference())); |
| 148 | + Element element = null; |
| 149 | + Log log = Log.instance(state.context); |
| 150 | + // Install a deferred diagnostic handler before calling DocTrees.getElement(DocTreePath) |
| 151 | + |
| 152 | + Log.DeferredDiagnosticHandler deferredDiagnosticHandler = deferredDiagnosticHandler(log); |
| 153 | + try { |
| 154 | + element = |
| 155 | + JavacTrees.instance(state.context) |
| 156 | + .getElement(new DocTreePath(getCurrentPath(), linkTree.getReference())); |
| 157 | + } catch (NullPointerException | AssertionError e) { |
| 158 | + // TODO: cushon - remove if https://bugs.openjdk.org/browse/JDK-8371248 is fixed |
| 159 | + } finally { |
| 160 | + log.popDiagnosticHandler(deferredDiagnosticHandler); |
| 161 | + } |
149 | 162 | // Don't warn about fully qualified types; they won't always be known at compile-time. |
150 | 163 | if (element != null || reference.contains(".")) { |
151 | 164 | return super.visitLink(linkTree, null); |
|
0 commit comments