Bug 470119 - ClassCastException: JDIPrimitiveValue cannot be cast to
IJavaVariable

Change-Id: I45b15737cc8f07de29e11f21683a26f63ccea374
Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.debug/+/186030
Tested-by: JDT Bot <jdt-bot@eclipse.org>
Reviewed-by: Sarika Sinha <sarika.sinha@in.ibm.com>
diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/AssignmentOperator.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/AssignmentOperator.java
index e86ca76..9b50463 100644
--- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/AssignmentOperator.java
+++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/instructions/AssignmentOperator.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -17,6 +17,7 @@
 import org.eclipse.jdt.debug.core.IJavaPrimitiveValue;
 import org.eclipse.jdt.debug.core.IJavaValue;
 import org.eclipse.jdt.debug.core.IJavaVariable;
+import org.eclipse.jdt.internal.debug.core.model.JDIPrimitiveValue;
 
 public class AssignmentOperator extends CompoundInstruction {
 
@@ -35,7 +36,40 @@
 	@Override
 	public void execute() throws CoreException {
 		IJavaValue value = popValue();
-		IJavaVariable variable = (IJavaVariable) pop();
+		Object val = pop();
+		IJavaVariable variable = null;
+		if (val instanceof IJavaVariable) {
+			variable = (IJavaVariable) val;
+		} else if (val instanceof JDIPrimitiveValue) {
+			JDIPrimitiveValue jdiPrimitiveValue = (JDIPrimitiveValue) val;
+			switch (fVariableTypeId) {
+				case T_boolean:
+					push(newValue(jdiPrimitiveValue.getBooleanValue()));
+					break;
+				case T_byte:
+					push(newValue(jdiPrimitiveValue.getByteValue()));
+					break;
+				case T_short:
+					push(newValue(jdiPrimitiveValue.getShortValue()));
+					break;
+				case T_char:
+					push(newValue(jdiPrimitiveValue.getCharValue()));
+					break;
+				case T_int:
+					push(newValue(jdiPrimitiveValue.getIntValue()));
+					break;
+				case T_long:
+					push(newValue(jdiPrimitiveValue.getLongValue()));
+					break;
+				case T_float:
+					push(newValue(jdiPrimitiveValue.getFloatValue()));
+					break;
+				case T_double:
+					push(newValue(jdiPrimitiveValue.getDoubleValue()));
+					break;
+			}
+			return;
+		}
 
 		if (value instanceof IJavaPrimitiveValue) {
 			IJavaPrimitiveValue primitiveValue = (IJavaPrimitiveValue) value;