IDEA-360567 Evaluate expression, where array is cast to subtype array inside a lambda that returns the cast result, results in EvaluateException

(cherry picked from commit c7e27f136dadd2d028eedda594b20a9111bbbe4e)

IJ-CR-147195

GitOrigin-RevId: 20f27cd9dfdd918ed4dc4567977b24793ac6a23b
This commit is contained in:
Egor Ushakov
2024-11-19 13:50:21 +00:00
committed by intellij-monorepo-bot
parent 00cf06cd4a
commit 478ed5f349
5 changed files with 17 additions and 9 deletions
@@ -106,11 +106,11 @@ public class BasicStepMethodFilter implements NamedMethodFilter {
return false;
}
String declaringClassNameName = myDeclaringClassName.getName(process);
boolean res = DebuggerUtilsEx.isAssignableFrom(declaringClassNameName, location.declaringType());
boolean res = DebuggerUtils.instanceOf(location.declaringType(), declaringClassNameName);
if (!res && !method.isStatic() && stackFrame != null) {
ObjectReference thisObject = stackFrame.thisObject();
if (thisObject != null) {
res = DebuggerUtilsEx.isAssignableFrom(declaringClassNameName, thisObject.referenceType());
res = DebuggerUtils.instanceOf(thisObject.referenceType(), (declaringClassNameName));
}
}
return res;
@@ -191,7 +191,7 @@ public class BasicStepMethodFilter implements NamedMethodFilter {
if (proxyValue != null) {
Type proxyType = proxyValue.type();
if (proxyType instanceof ReferenceType &&
DebuggerUtilsEx.isAssignableFrom(myDeclaringClassName.getName(process), proxyType)) {
DebuggerUtils.instanceOf(proxyType, myDeclaringClassName.getName(process))) {
Value methodValue = argumentValues.get(size - 2);
if (methodValue instanceof ObjectReference) {
// TODO: no signature check for now
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
/*
* @author Eugene Zhuravlev
@@ -198,7 +198,7 @@ public class RequestHint {
}
}
if (settings.SKIP_CLASSLOADERS && DebuggerUtilsEx.isAssignableFrom("java.lang.ClassLoader", location.declaringType())) {
if (settings.SKIP_CLASSLOADERS && DebuggerUtils.instanceOf(location.declaringType(), "java.lang.ClassLoader")) {
return StepRequest.STEP_OUT;
}
}
@@ -2,11 +2,11 @@
package com.intellij.debugger.engine.evaluation.expression;
import com.intellij.debugger.JavaDebuggerBundle;
import com.intellij.debugger.engine.DebuggerUtils;
import com.intellij.debugger.engine.JVMName;
import com.intellij.debugger.engine.evaluation.EvaluateException;
import com.intellij.debugger.engine.evaluation.EvaluateExceptionUtil;
import com.intellij.debugger.engine.evaluation.EvaluationContextImpl;
import com.intellij.debugger.impl.DebuggerUtilsEx;
import com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
@@ -51,9 +51,15 @@ public class SyntheticVariableEvaluator implements Evaluator {
@Override
public void setValue(Value value) throws EvaluateException {
if (value != null) {
if (value == null) {
if (myTypeNameString != null && DebuggerUtils.isPrimitiveType(myTypeNameString)) {
throw EvaluateExceptionUtil.createEvaluateException(
JavaDebuggerBundle.message("evaluation.error.cannot.set.primitive.to.null"));
}
}
else {
Type type = value.type();
if (myTypeNameString != null && !DebuggerUtilsEx.isAssignableFrom(myTypeNameString, type)) {
if (myTypeNameString != null && !DebuggerUtils.instanceOf(type, myTypeNameString)) {
throw EvaluateExceptionUtil.createEvaluateException(
JavaDebuggerBundle.message("evaluation.error.cannot.cast.object", type.name(), myTypeNameString));
}
@@ -123,7 +123,7 @@ public abstract class DebuggerUtilsEx extends DebuggerUtils {
return null;
}
@Deprecated
public static boolean isAssignableFrom(@NotNull String baseQualifiedName, @NotNull Type checkedType) {
if (checkedType instanceof ReferenceType) {
if (CommonClassNames.JAVA_LANG_OBJECT.equals(baseQualifiedName)) {
@@ -134,6 +134,7 @@ public abstract class DebuggerUtilsEx extends DebuggerUtils {
return baseQualifiedName.equals(checkedType.name());
}
@Deprecated
public static ReferenceType getSuperClass(@NotNull final String baseQualifiedName, @NotNull ReferenceType checkedType) {
if (baseQualifiedName.equals(checkedType.name())) {
return checkedType;
@@ -151,6 +151,7 @@ evaluation.error.cannot.cast.numeric=Cannot cast numeric value to ''{0}''
evaluation.error.cannot.cast.boolean=Cannot cast boolean value to ''{0}''
evaluation.error.cannot.cast.char=Cannot cast char value to ''{0}''
evaluation.error.cannot.cast.object=Cannot cast ''{0}'' to ''{1}''
evaluation.error.cannot.set.primitive.to.null=Can't set a primitive type to null
evaluation.error.numeric.expected=Numeric value expected
evaluation.error.integer.expected=Integer value expected
evaluation.error.boolean.expected=Boolean value expected