diff --git a/src/main/kotlin/com/netflix/java/refactor/ast/AstParser.kt b/src/main/kotlin/com/netflix/java/refactor/ast/AstParser.kt index 36acd0b..d8aa055 100644 --- a/src/main/kotlin/com/netflix/java/refactor/ast/AstParser.kt +++ b/src/main/kotlin/com/netflix/java/refactor/ast/AstParser.kt @@ -63,7 +63,12 @@ class AstParser(val classpath: Iterable?) { .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 } diff --git a/src/test/kotlin/com/netflix/java/refactor/ast/AstScannerTest.kt b/src/test/kotlin/com/netflix/java/refactor/ast/AstParserTest.kt similarity index 74% rename from src/test/kotlin/com/netflix/java/refactor/ast/AstScannerTest.kt rename to src/test/kotlin/com/netflix/java/refactor/ast/AstParserTest.kt index 08da831..dacfd37 100644 --- a/src/test/kotlin/com/netflix/java/refactor/ast/AstScannerTest.kt +++ b/src/test/kotlin/com/netflix/java/refactor/ast/AstParserTest.kt @@ -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 c = s -> { + | Function f = s2 -> null; + | }; + | } + |} + """) + + parseJava(a) + } @Test - fun scannerIsAbleToIdentifyTypesFromExternalDependencies() { + fun parserIsAbleToIdentifyTypesFromExternalDependencies() { val a = java(""" |package a; |import org.testng.annotations.*; @@ -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")