Don't throw exceptions on unexpected annotation arguments in class file reader
This commit is contained in:
+2
-16
@@ -16,9 +16,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.kotlin.header
|
||||
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinClass
|
||||
import org.jetbrains.kotlin.load.java.AbiVersionUtil
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinClass
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass
|
||||
|
||||
public class KotlinClassHeader(
|
||||
public val kind: KotlinClassHeader.Kind,
|
||||
@@ -29,20 +29,6 @@ public class KotlinClassHeader(
|
||||
) {
|
||||
public val isCompatibleAbiVersion: Boolean get() = AbiVersionUtil.isAbiVersionCompatible(version)
|
||||
|
||||
init {
|
||||
if (isCompatibleAbiVersion) {
|
||||
assert((annotationData == null) == (kind != Kind.CLASS && kind != Kind.PACKAGE_FACADE)) {
|
||||
"Annotation data should be not null only for CLASS and PACKAGE_FACADE (kind=$kind)"
|
||||
}
|
||||
assert((syntheticClassKind == null) == (kind != Kind.SYNTHETIC_CLASS)) {
|
||||
"Synthetic class kind should be present for SYNTHETIC_CLASS (kind=$kind)"
|
||||
}
|
||||
assert((classKind == null) == (kind != Kind.CLASS)) {
|
||||
"Class kind should be present for CLASS (kind=$kind)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum class Kind {
|
||||
CLASS,
|
||||
PACKAGE_FACADE,
|
||||
|
||||
+8
-42
@@ -29,7 +29,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.kotlin.load.java.AbiVersionUtil.isAbiVersionCompatible;
|
||||
import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.*;
|
||||
import static org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass.*;
|
||||
import static org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader.Kind.*;
|
||||
@@ -109,7 +108,7 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor
|
||||
case SYNTHETIC_CLASS:
|
||||
return new SyntheticClassHeaderReader();
|
||||
default:
|
||||
throw new IllegalStateException("Unknown kind: " + newKind);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,24 +134,18 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor
|
||||
@Override
|
||||
public void visit(@Nullable Name name, @Nullable Object value) {
|
||||
if (name != null && name.asString().equals(ABI_VERSION_FIELD_NAME)) {
|
||||
version = value == null ? AbiVersionUtil.INVALID_VERSION : (Integer) value;
|
||||
}
|
||||
else {
|
||||
unexpectedArgument(name);
|
||||
version = value instanceof Integer ? (Integer) value : AbiVersionUtil.INVALID_VERSION;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public AnnotationArrayArgumentVisitor visitArray(@NotNull Name name) {
|
||||
if (name.asString().equals(DATA_FIELD_NAME)) {
|
||||
return stringArrayVisitor();
|
||||
}
|
||||
else if (isAbiVersionCompatible(version)) {
|
||||
throw new IllegalStateException("Unexpected array argument " + name + " for annotation " + annotationClassName);
|
||||
}
|
||||
return name.asString().equals(DATA_FIELD_NAME) ? stringArrayVisitor() : null;
|
||||
}
|
||||
|
||||
return null;
|
||||
@Override
|
||||
public void visitEnum(@NotNull Name name, @NotNull ClassId enumClassId, @NotNull Name enumEntryName) {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -167,16 +160,13 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor
|
||||
return new AnnotationArrayArgumentVisitor() {
|
||||
@Override
|
||||
public void visit(@Nullable Object value) {
|
||||
if (!(value instanceof String)) {
|
||||
throw new IllegalStateException("Unexpected argument value: " + value);
|
||||
if (value instanceof String) {
|
||||
strings.add((String) value);
|
||||
}
|
||||
|
||||
strings.add((String) value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnum(@NotNull ClassId enumClassId, @NotNull Name enumEntryName) {
|
||||
unexpectedArgument(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -187,21 +177,6 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected AnnotationArrayArgumentVisitor unexpectedArgument(@Nullable Name name) {
|
||||
if (isAbiVersionCompatible(version)) {
|
||||
throw new IllegalStateException("Unexpected argument " + name + " for annotation " + annotationClassName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void unexpectedEnumArgument(@NotNull Name name, @NotNull ClassId enumClassId, @NotNull Name enumEntryName) {
|
||||
if (isAbiVersionCompatible(version)) {
|
||||
throw new IllegalStateException("Unexpected enum entry for class annotation " + annotationClassName + ": " +
|
||||
name + "=" + enumClassId + "." + enumEntryName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnd() {
|
||||
}
|
||||
@@ -216,9 +191,7 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor
|
||||
public void visitEnum(@NotNull Name name, @NotNull ClassId enumClassId, @NotNull Name enumEntryName) {
|
||||
if (KotlinClass.KIND_CLASS_ID.equals(enumClassId) && KIND_FIELD_NAME.equals(name.asString())) {
|
||||
classKind = valueOfOrNull(KotlinClass.Kind.class, enumEntryName.asString());
|
||||
if (classKind != null) return;
|
||||
}
|
||||
unexpectedEnumArgument(name, enumClassId, enumEntryName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,11 +199,6 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor
|
||||
public PackageHeaderReader() {
|
||||
super(JvmClassName.byFqNameWithoutInnerClasses(KOTLIN_PACKAGE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnum(@NotNull Name name, @NotNull ClassId enumClassId, @NotNull Name enumEntryName) {
|
||||
unexpectedEnumArgument(name, enumClassId, enumEntryName);
|
||||
}
|
||||
}
|
||||
|
||||
private class SyntheticClassHeaderReader extends HeaderAnnotationArgumentVisitor {
|
||||
@@ -242,9 +210,7 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor
|
||||
public void visitEnum(@NotNull Name name, @NotNull ClassId enumClassId, @NotNull Name enumEntryName) {
|
||||
if (KotlinSyntheticClass.KIND_CLASS_ID.equals(enumClassId) && KIND_FIELD_NAME.equals(name.asString())) {
|
||||
syntheticClassKind = valueOfOrNull(KotlinSyntheticClass.Kind.class, enumEntryName.asString());
|
||||
if (syntheticClassKind != null) return;
|
||||
}
|
||||
unexpectedEnumArgument(name, enumClassId, enumEntryName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user