From 2b541a560ea8a19f93cf3c558fb81d302b44939e Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 14 Jul 2015 21:19:44 +0300 Subject: [PATCH] Make function references compiled with old compiler work with new runtime --- .../jvm/internal/ReflectionFactoryImpl.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java index 6f86ff69d36..27f730367ef 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java @@ -16,6 +16,7 @@ package kotlin.reflect.jvm.internal; +import kotlin.jvm.KotlinReflectionNotSupportedError; import kotlin.jvm.internal.*; import kotlin.reflect.*; @@ -43,7 +44,19 @@ public class ReflectionFactoryImpl extends ReflectionFactory { @Override public KFunction function(FunctionReference f) { - return new KFunctionFromReferenceImpl(f); + try { + return new KFunctionFromReferenceImpl(f); + } + catch (KotlinReflectionNotSupportedError e) { + // If this function reference is compiled with an older compiler, it doesn't have the newer methods + // (getName(), getOwner(), getSignature()), so the default implementation from FunctionReference will be invoked + // and KotlinReflectionNotSupportedError will be thrown. + // Instead it's much better to use the reference as a KFunction. Yes, it will throw "no kotlin-reflect.jar was found" + // exceptions even if it exists in the classpath. However, at least it can be used as a function (invoke() will work). + // Moreover, old function references were not supposed to be introspected anyway because there was no reflection API back then. + // TODO: drop after M13 + return f; + } } // Properties