From d540ff8890b540703d3cbdfd662f35a722b1d0d1 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Thu, 9 Jul 2015 10:41:47 +0300 Subject: [PATCH] KT-8206 java.lang.NoSuchFieldError: $kotlinClass for deprecated::class Instantiate class literals for annotation classes as foreign. --- .../org/jetbrains/kotlin/codegen/ExpressionCodegen.java | 5 ++++- .../reflection/classLiterals/annotationClassLiteral.kt | 7 +++++++ .../generated/BlackBoxWithStdlibCodegenTestGenerated.java | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/boxWithStdlib/reflection/classLiterals/annotationClassLiteral.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 2e698b7203e..f9466586266 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -2795,7 +2795,10 @@ public class ExpressionCodegen extends JetVisitor implem ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor(); //noinspection ConstantConditions ModuleDescriptor module = DescriptorUtils.getContainingModule(descriptor); - if (descriptor instanceof JavaClassDescriptor || module == module.getBuiltIns().getBuiltInsModule()) { + // Instantiate annotation classes as foreign due to bug in JDK 6 and 7: + // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6857918 + if (descriptor instanceof JavaClassDescriptor || module == module.getBuiltIns().getBuiltInsModule() || + DescriptorUtils.isAnnotationClass(descriptor)) { putJavaLangClassInstance(v, classAsmType); wrapJavaClassIntoKClass(v); } diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/classLiterals/annotationClassLiteral.kt b/compiler/testData/codegen/boxWithStdlib/reflection/classLiterals/annotationClassLiteral.kt new file mode 100644 index 00000000000..a567b7f80af --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/classLiterals/annotationClassLiteral.kt @@ -0,0 +1,7 @@ +import kotlin.test.assertEquals + +fun box(): String { + assertEquals("deprecated", deprecated::class.simpleName) + + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java index cc474679aff..2407669c3b4 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java @@ -2751,6 +2751,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/reflection/classLiterals"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("annotationClassLiteral.kt") + public void testAnnotationClassLiteral() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/classLiterals/annotationClassLiteral.kt"); + doTestWithStdlib(fileName); + } + @TestMetadata("arrays.kt") public void testArrays() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/classLiterals/arrays.kt");