From 17b4a5a15ccc5cf32dd6cc74f39b6ad332a8d32c Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Mon, 28 Jan 2013 21:22:29 +0400 Subject: [PATCH] EA-43240 - AIOOBE: ClassReader.a Index out of bounds from ASM --- .../versions/KotlinAbiVersionIndex.java | 56 +++++++++++-------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/versions/KotlinAbiVersionIndex.java b/idea/src/org/jetbrains/jet/plugin/versions/KotlinAbiVersionIndex.java index e44dd71793e..7b8c9fd228f 100644 --- a/idea/src/org/jetbrains/jet/plugin/versions/KotlinAbiVersionIndex.java +++ b/idea/src/org/jetbrains/jet/plugin/versions/KotlinAbiVersionIndex.java @@ -17,6 +17,7 @@ package org.jetbrains.jet.plugin.versions; import com.google.common.collect.Maps; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.util.Ref; import com.intellij.openapi.vfs.VirtualFile; @@ -31,12 +32,14 @@ import org.jetbrains.asm4.Opcodes; import org.jetbrains.jet.lang.resolve.java.AbiVersionUtil; import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; +import java.lang.Throwable; import java.util.Map; /** * Important! This is not a stub-based index. And it has its own version */ public class KotlinAbiVersionIndex extends ScalarIndexExtension { + private static final Logger LOG = Logger.getInstance(KotlinAbiVersionIndex.class); public static final KotlinAbiVersionIndex INSTANCE = new KotlinAbiVersionIndex(); @@ -58,32 +61,37 @@ public class KotlinAbiVersionIndex extends ScalarIndexExtension { final Map result = Maps.newHashMap(); final Ref annotationPresent = new Ref(false); - ClassReader classReader = new ClassReader(inputData.getContent()); - classReader.accept(new ClassVisitor(Opcodes.ASM4) { - @Override - public AnnotationVisitor visitAnnotation(String desc, boolean visible) { - if (!JvmStdlibNames.JET_CLASS.getDescriptor().equals(desc) && - !JvmStdlibNames.JET_PACKAGE_CLASS.getDescriptor().equals(desc)) { - return null; - } - annotationPresent.set(true); - return new AnnotationVisitor(Opcodes.ASM4) { - @Override - public void visit(String name, Object value) { - if (JvmStdlibNames.ABI_VERSION_NAME.equals(name)) { - if (value instanceof Integer) { - Integer abiVersion = (Integer) value; - result.put(abiVersion, null); - } - else { - // Version is set to something weird - result.put(AbiVersionUtil.INVALID_VERSION, null); + try { + ClassReader classReader = new ClassReader(inputData.getContent()); + classReader.accept(new ClassVisitor(Opcodes.ASM4) { + @Override + public AnnotationVisitor visitAnnotation(String desc, boolean visible) { + if (!JvmStdlibNames.JET_CLASS.getDescriptor().equals(desc) && + !JvmStdlibNames.JET_PACKAGE_CLASS.getDescriptor().equals(desc)) { + return null; + } + annotationPresent.set(true); + return new AnnotationVisitor(Opcodes.ASM4) { + @Override + public void visit(String name, Object value) { + if (JvmStdlibNames.ABI_VERSION_NAME.equals(name)) { + if (value instanceof Integer) { + Integer abiVersion = (Integer) value; + result.put(abiVersion, null); + } + else { + // Version is set to something weird + result.put(AbiVersionUtil.INVALID_VERSION, null); + } } } - } - }; - } - }, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES); + }; + } + }, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES); + } + catch (Throwable e) { + LOG.warn("Indexing ABI version for file " + inputData.getFile(), e); + } if (annotationPresent.get() && result.isEmpty()) { // No version at all: the class is too old