From 6d967c326da0cec709769c93b8e5b118f21c6182 Mon Sep 17 00:00:00 2001 From: Johann Martinache Date: Wed, 27 Mar 2019 12:32:18 +0000 Subject: [PATCH 1/3] Fix an issue when trying to resolve an non source file It seems that in some cases the plugin is trying to resolve files who are not part of the workspace, due to either their temporary nature, or other IDE or tool file. In my case, it was trying to resole files from the vim .undodir directory, was failing to parse those files due to their binary nature, and the whole sourceset resolution was failing in consequence. To avoid that issue add a try catch around the file reading method to ensure exception are not fired, and the resolution does not break. --- server/src/main/kotlin/org/javacs/kt/SourceFiles.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt b/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt index abb2a6ff7..87b2dcbf9 100644 --- a/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt +++ b/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt @@ -106,7 +106,13 @@ class SourceFiles(private val sp: SourcePath) { private fun readFromDisk(file: Path): SourceVersion? { if (!Files.exists(file)) return null - val content = Files.readAllLines(file).joinToString("\n") + var content = "" + + try { + content = Files.readAllLines(file).joinToString("\n") + } catch(exception:Exception) { + LOG.debug("Exception while parsing source file : ${file.toFile().absolutePath}") + } return SourceVersion(content, -1) } From a8fafc41893e3c72dc1797a8fd692ea5d7f6908d Mon Sep 17 00:00:00 2001 From: Johann Martinache Date: Fri, 29 Mar 2019 09:46:18 +0000 Subject: [PATCH 2/3] Change logging level in case of exceptions Raise the level of verbosing level in case of an exception while parsing a source set file to `warn`. --- server/src/main/kotlin/org/javacs/kt/SourceFiles.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt b/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt index 87b2dcbf9..01bfb3552 100644 --- a/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt +++ b/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt @@ -111,7 +111,7 @@ class SourceFiles(private val sp: SourcePath) { try { content = Files.readAllLines(file).joinToString("\n") } catch(exception:Exception) { - LOG.debug("Exception while parsing source file : ${file.toFile().absolutePath}") + LOG.warn("Exception while parsing source file : ${file.toFile().absolutePath}") } return SourceVersion(content, -1) From fbe2e196f310a0d97c9753961e94e5dc897c65ad Mon Sep 17 00:00:00 2001 From: Johann Martinache Date: Mon, 1 Apr 2019 11:02:01 +0100 Subject: [PATCH 3/3] No more capture all exceptions Catch only IOException for now, being the issue we are encountering now. That try/catch block can be removed, when the `.gitignore` file content is taken into account. --- server/src/main/kotlin/org/javacs/kt/SourceFiles.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt b/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt index 01bfb3552..416bd1b8d 100644 --- a/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt +++ b/server/src/main/kotlin/org/javacs/kt/SourceFiles.kt @@ -110,7 +110,7 @@ class SourceFiles(private val sp: SourcePath) { try { content = Files.readAllLines(file).joinToString("\n") - } catch(exception:Exception) { + } catch(exception: IOException) { LOG.warn("Exception while parsing source file : ${file.toFile().absolutePath}") }