[r=nik] catch unexpected errors when parsing class files and emit compilation warnings (IDEA-104818 External build: Error in compiler)

This commit is contained in:
Eugene Zhuravlev
2013-04-09 14:09:43 +04:00
parent 67d5dc796a
commit 9255859e2b
2 changed files with 15 additions and 3 deletions
@@ -15,6 +15,7 @@
*/
package org.jetbrains.jps.incremental.java;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.io.FileUtil;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
@@ -39,6 +40,7 @@ import java.util.Set;
* Date: 2/16/12
*/
class OutputFilesSink implements OutputFileConsumer {
private static final Logger LOG = Logger.getInstance("#org.jetbrains.jps.incremental.java.OutputFilesSink");
private final CompileContext myContext;
private final ModuleLevelBuilder.OutputConsumer myOutputConsumer;
private final Callbacks.Backend myMappingsCallback;
@@ -84,8 +86,18 @@ class OutputFilesSink implements OutputFileConsumer {
if (!isTemp && outKind == JavaFileObject.Kind.CLASS && !Utils.errorsDetected(myContext)) {
// register in mappings any non-temp class file
final ClassReader reader = new ClassReader(content.getBuffer(), content.getOffset(), content.getLength());
myMappingsCallback.associate(FileUtil.toSystemIndependentName(fileObject.getFile().getPath()), sourcePath, reader);
try {
final ClassReader reader = new ClassReader(content.getBuffer(), content.getOffset(), content.getLength());
myMappingsCallback.associate(FileUtil.toSystemIndependentName(fileObject.getFile().getPath()), sourcePath, reader);
}
catch (Throwable e) {
// need this to make sure that unexpected errors in, for example, ASM will not ruin the compilation
final String message = "Class dependency information may be incomplete! Error parsing generated class " + fileObject.getFile().getPath();
LOG.info(message, e);
myContext.processMessage(new CompilerMessage(
JavaBuilder.BUILDER_NAME, BuildMessage.Kind.WARNING, message + "\n" + CompilerMessage.getTextFromThrowable(e), sourcePath)
);
}
}
}
@@ -97,7 +97,7 @@ public class CompilerMessage extends BuildMessage {
return getCompilerName() + ":" + getKind().name() + ":" + super.toString();
}
private static String getTextFromThrowable(Throwable internalError) {
public static String getTextFromThrowable(Throwable internalError) {
StringBuilder text = new StringBuilder();
text.append("Error: ");
final String msg = internalError.getMessage();