Skip to content

Commit 3d447c7

Browse files
authored
Merge pull request #356 from olafurpg/issue-319
2 parents f6086d5 + 8c5366b commit 3d447c7

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.sourcegraph.semanticdb_javac;
2+
3+
public class CompilationUnitException extends Throwable {
4+
public CompilationUnitException(String compilationUnit, Throwable cause) {
5+
super(compilationUnit, cause);
6+
}
7+
8+
@Override
9+
public Throwable fillInStackTrace() {
10+
return this;
11+
}
12+
}

semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbTaskListener.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,17 @@ public void finished(TaskEvent e) {
4444
if (e.getKind() != TaskEvent.Kind.ANALYZE) return;
4545
try {
4646
onFinishedAnalyze(e);
47-
} catch (Exception ex) {
47+
} catch (Throwable ex) {
4848
// Catch exceptions because we don't want to stop the compilation even if this plugin has a
4949
// bug. We report the full stack trace because it's helpful for bug reports. Exceptions
5050
// should only happen in *exceptional* situations and they should be reported upstream.
51-
reporter.exception(ex);
51+
Throwable throwable = ex;
52+
if (e.getSourceFile() != null) {
53+
throwable =
54+
new CompilationUnitException(
55+
String.valueOf(e.getSourceFile().toUri().toString()), throwable);
56+
}
57+
reporter.exception(throwable);
5258
}
5359
}
5460

semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbVisitor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ public Void visitClass(ClassTree node, Void unused) {
153153
List<JCTree.JCTypeParameter> typeParameters = cls.getTypeParameters();
154154
int i = 0;
155155
for (Symbol.TypeVariableSymbol typeSym : cls.sym.getTypeParameters()) {
156+
if (i >= typeParameters.size()) {
157+
// Happens in testcontainers/testcontainers-java, see
158+
// https://github.com/sourcegraph/lsif-java/issues/319
159+
// Failed to reproduce with a minimal source file so we don't have a test case that hits
160+
// this branch.
161+
break;
162+
}
156163
emitSymbolOccurrence(
157164
typeSym,
158165
typeParameters.get(i),

0 commit comments

Comments
 (0)