Add additional exception info if StringReference doesn't resolve to a String

This commit is contained in:
Ben Gruver 2016-10-23 13:55:23 -07:00
parent 8f7d1a897d
commit 7a95aa296f
2 changed files with 11 additions and 4 deletions

View File

@ -32,6 +32,8 @@
package org.jf.smalidea.debugging.value; package org.jf.smalidea.debugging.value;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiSubstitutor;
import com.sun.jdi.ObjectReference;
import com.sun.jdi.StringReference; import com.sun.jdi.StringReference;
import org.jf.smalidea.psi.impl.SmaliMethod; import org.jf.smalidea.psi.impl.SmaliMethod;
@ -41,6 +43,11 @@ public class LazyStringReference extends LazyObjectReference<StringReference> im
} }
public String value() { public String value() {
ObjectReference objectReference = getValue();
if (!(objectReference instanceof StringReference)) {
throw new IllegalStateException(String.format("Expecting type String, but got %s. method=%s, register=%d",
objectReference.type().name(), this.method.getSignature(PsiSubstitutor.EMPTY), registerNumber));
}
return getValue().value(); return getValue().value();
} }
} }

View File

@ -48,10 +48,10 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class LazyValue<T extends Value> implements Value { public class LazyValue<T extends Value> implements Value {
private final int registerNumber; protected final int registerNumber;
private final Project project; protected final Project project;
private final SmaliMethod method; protected final SmaliMethod method;
private final String type; protected final String type;
private EvaluationContext evaluationContext; private EvaluationContext evaluationContext;
private Value value; private Value value;