Fix compilation of Kotlin code when there's kotlin-reflect library in the classpath, but it's actually not used by Kotlin code. See #345

This commit is contained in:
Alexey Andreev 2018-06-18 22:56:11 +03:00
parent cdffb779e0
commit dc99ead514

View File

@ -116,7 +116,7 @@ public class ClassForNameTransformer implements ClassHolderTransformer {
if (nameIndex >= 0) { if (nameIndex >= 0) {
representative = program.variableAt(nameRepresentatives[nameIndex]); representative = program.variableAt(nameRepresentatives[nameIndex]);
} else if (constant != null) { } else if (constant != null) {
if (classSource.get(constant) == null) { if (classSource.get(constant) == null || !filterClassName(constant)) {
continue; continue;
} }
ClassConstantInstruction classConstant = new ClassConstantInstruction(); ClassConstantInstruction classConstant = new ClassConstantInstruction();
@ -148,4 +148,18 @@ public class ClassForNameTransformer implements ClassHolderTransformer {
} }
} }
} }
private boolean filterClassName(String className) {
switch (className) {
// It's a hack for Kotlin. Kotlin full reflection library is too heavyweight for TeaVM.
// This optimization enables full reflection when there's Kotlin/JVM reflection library
// in the classpath, since Kotlin uses Class.forName() to check whether there's
// full reflection library presents. If program does not use full reflection,
// but build configuration includes kotlin-reflect artifact as a dependency,
// it gets into classpath, which allows this optimization to be applied.
case "kotlin.reflect.jvm.internal.ReflectionFactoryImpl":
return false;
}
return true;
}
} }