Skip to content

Commit

Permalink
Trap exceptions in attribution when symbol entering fails
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider committed Aug 23, 2016
1 parent 5692b0f commit 6842e5f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/main/kotlin/com/netflix/java/refactor/ast/AstParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ class AstParser(val classpath: Iterable<Path>?) {
.map { compiler.parse(it) }
.enterAll()

compiler.attribute(compiler.todo)
try {
compiler.attribute(compiler.todo)
} catch(ignore: Throwable) {
// when symbol entering fails on problems like missing types, attribution can often times proceed
// unhindered, but it sometimes cannot (so attribution is always a BEST EFFORT in the presence of errors)
}

return cus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,30 @@ import java.nio.file.Files
import java.util.zip.ZipInputStream
import kotlin.test.assertEquals

class AstScannerTest : AbstractRefactorTest() {
class AstParserTest : AbstractRefactorTest() {

/**
* Often type attribution can succeed in spite of symbol entering failures, but there are edge cases
* where it does not. Therefore, attribution after symbol entering failures is always a BEST EFFORT only.
*/
@Test
fun typeAttributionDoesNotCauseRuntimeExceptionsWhenSymbolEnteringFails() {
val a = java("""
|import java.util.function.Consumer;
|public class A {
| public void fail(){
| Consumer<String> c = s -> {
| Function<String, OOPS> f = s2 -> null;
| };
| }
|}
""")

parseJava(a)
}

@Test
fun scannerIsAbleToIdentifyTypesFromExternalDependencies() {
fun parserIsAbleToIdentifyTypesFromExternalDependencies() {
val a = java("""
|package a;
|import org.testng.annotations.*;
Expand Down Expand Up @@ -47,7 +67,7 @@ class AstScannerTest : AbstractRefactorTest() {
// FIXME how to do this?
@Ignore
@Test
fun scannerIsAbleToLoadExternalDependenciesFromInMemoryFileSystems() {
fun parserIsAbleToLoadExternalDependenciesFromInMemoryFileSystems() {
val fs = MemoryFileSystemBuilder.newEmpty().build("virtual")
fs.use { fs ->
val a = fs.getPath("A.java")
Expand Down

0 comments on commit 6842e5f

Please sign in to comment.