NoSuchFieldError in Evaluate Expression on a property of a derived class (KT-12206)
#KT-12206 Fixed
This commit is contained in:
@@ -250,6 +250,7 @@
|
||||
- [`KT-11967`](https://youtrack.jetbrains.com/issue/KT-11967) Fix Find Usages/Rename for parameter references in XML files
|
||||
- [`KT-10770`](https://youtrack.jetbrains.com/issue/KT-10770) "Optimize imports" will not keep import if a type is only referenced by kdoc
|
||||
- [`KT-11955`](https://youtrack.jetbrains.com/issue/KT-11955) Copy/Paste inserts fully qualified name when copying function with overloads
|
||||
- [`KT-12206`](https://youtrack.jetbrains.com/issue/KT-12206) Fix NoSuchFieldError on accessing base property without backing field in evaluate expression
|
||||
|
||||
|
||||
### Reflection
|
||||
|
||||
@@ -48,7 +48,6 @@ import org.jetbrains.kotlin.types.KotlinType;
|
||||
import java.io.File;
|
||||
|
||||
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.LOCAL_VARIABLE_DELEGATE;
|
||||
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.LOCAL_VARIABLE_PROPERTY_METADATA;
|
||||
import static org.jetbrains.kotlin.descriptors.Modality.ABSTRACT;
|
||||
import static org.jetbrains.kotlin.descriptors.Modality.FINAL;
|
||||
import static org.jetbrains.kotlin.resolve.BindingContext.DELEGATED_PROPERTY_CALL;
|
||||
@@ -151,8 +150,14 @@ public class JvmCodegenUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only properties of the same class can be directly accessed, except when we are evaluating expressions in the debugger
|
||||
if (!isCallInsideSameClassAsDeclared(property, context) && !isDebuggerContext(context)) return false;
|
||||
if (!isDebuggerContext(context)) {
|
||||
// Unless we are evaluating expression in debugger context, only properties of the same class can be directly accessed
|
||||
if (!isCallInsideSameClassAsDeclared(property, context)) return false;
|
||||
}
|
||||
else {
|
||||
// In debugger we want to access through accessors if they are present. If property overrides something accessors must be present.
|
||||
if (!property.getOverriddenDescriptors().isEmpty()) return false;
|
||||
}
|
||||
|
||||
// Delegated and extension properties have no backing fields
|
||||
if (isDelegated || property.getExtensionReceiverParameter() != null) return false;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package b
|
||||
|
||||
abstract class B {
|
||||
open val propWithFinal: Int
|
||||
get() = 1
|
||||
|
||||
open val propWithNonFinal: Int
|
||||
get() = 2
|
||||
}
|
||||
|
||||
abstract class Base: B() {
|
||||
override final val propWithFinal: Int = 3
|
||||
override val propWithNonFinal: Int = 4
|
||||
|
||||
fun fooFinal() = this.propWithFinal
|
||||
fun fooNonFinal() = this.propWithNonFinal
|
||||
}
|
||||
|
||||
// 2 GETFIELD b/Base.propWithFinal : I
|
||||
// 1 INVOKEVIRTUAL b/Base.getPropWithNonFinal \(\)I
|
||||
@@ -31,6 +31,12 @@ import java.util.regex.Pattern;
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
|
||||
@TestMetadata("accessorForOverridenVal.kt")
|
||||
public void testAccessorForOverridenVal() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/accessorForOverridenVal.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("accessorForProtected.kt")
|
||||
public void testAccessorForProtected() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/accessorForProtected.kt");
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
LineBreakpoint created at accessToOverridenPropertyWithBackingField.kt:12
|
||||
!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !OUTPUT_PATH!;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! accessToOverridenPropertyWithBackingField.AccessToOverridenPropertyWithBackingFieldKt
|
||||
Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
|
||||
accessToOverridenPropertyWithBackingField.kt:12
|
||||
Compile bytecode for d.prop
|
||||
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
|
||||
|
||||
Process finished with exit code 0
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
LineBreakpoint created at kt12206BasePropertyWithoutBackingField.kt:13
|
||||
!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !OUTPUT_PATH!;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! kt12206BasePropertyWithoutBackingField.Kt12206BasePropertyWithoutBackingFieldKt
|
||||
Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
|
||||
kt12206BasePropertyWithoutBackingField.kt:13
|
||||
Compile bytecode for d.prop
|
||||
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
|
||||
|
||||
Process finished with exit code 0
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package accessToOverridenPropertyWithBackingField
|
||||
|
||||
open class B1 {
|
||||
val prop = "OK"
|
||||
}
|
||||
|
||||
class D1: B1()
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val d = D1()
|
||||
//Breakpoint!
|
||||
d.prop // <-- breakpoint here
|
||||
}
|
||||
|
||||
// EXPRESSION: d.prop
|
||||
// RESULT: "OK": Ljava/lang/String;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package kt12206BasePropertyWithoutBackingField
|
||||
|
||||
abstract class Base {
|
||||
val prop: String?
|
||||
get() = "OK"
|
||||
}
|
||||
|
||||
class Derived : Base()
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val d = Derived()
|
||||
//Breakpoint!
|
||||
d.prop // <-- breakpoint here
|
||||
}
|
||||
|
||||
// EXPRESSION: d.prop
|
||||
// RESULT: "OK": Ljava/lang/String;
|
||||
+12
@@ -39,6 +39,12 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
|
||||
doSingleBreakpointTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("accessToOverridenPropertyWithBackingField.kt")
|
||||
public void testAccessToOverridenPropertyWithBackingField() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/accessToOverridenPropertyWithBackingField.kt");
|
||||
doSingleBreakpointTest(fileName);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInSingleBreakpoint() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
@@ -205,6 +211,12 @@ public class KotlinEvaluateExpressionTestGenerated extends AbstractKotlinEvaluat
|
||||
doSingleBreakpointTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt12206BasePropertyWithoutBackingField.kt")
|
||||
public void testKt12206BasePropertyWithoutBackingField() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/kt12206BasePropertyWithoutBackingField.kt");
|
||||
doSingleBreakpointTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt5554OnlyIntsShouldBeCoerced.kt")
|
||||
public void testKt5554OnlyIntsShouldBeCoerced() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/debugger/tinyApp/src/evaluate/singleBreakpoint/kt5554OnlyIntsShouldBeCoerced.kt");
|
||||
|
||||
Reference in New Issue
Block a user