From ce28e2bcb6d2a6ac0112aa24b4b19c3a44953fc0 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 21 Jan 2015 13:26:01 +0300 Subject: [PATCH] IDEA-135439 Unable to use Boolean breakpoint condition --- .../ConditionalExpressionEvaluator.java | 7 +++---- .../expression/DoWhileStatementEvaluator.java | 4 ++-- .../expression/ForStatementEvaluatorBase.java | 4 ++-- .../expression/IfStatementEvaluator.java | 4 ++-- .../evaluation/expression/UnBoxingEvaluator.java | 15 +++++++++------ .../expression/WhileStatementEvaluator.java | 4 ++-- .../debugger/ui/breakpoints/Breakpoint.java | 5 +++-- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/ConditionalExpressionEvaluator.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/ConditionalExpressionEvaluator.java index 7eacd4ace313..fd90cd6ca773 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/ConditionalExpressionEvaluator.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/ConditionalExpressionEvaluator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ import com.intellij.debugger.engine.evaluation.EvaluateException; import com.intellij.debugger.engine.evaluation.EvaluateExceptionUtil; import com.intellij.debugger.engine.evaluation.EvaluationContextImpl; import com.sun.jdi.BooleanValue; -import com.sun.jdi.Value; class ConditionalExpressionEvaluator implements Evaluator { private final Evaluator myConditionEvaluator; @@ -45,8 +44,8 @@ class ConditionalExpressionEvaluator implements Evaluator { @Override public Object evaluate(EvaluationContextImpl context) throws EvaluateException { - Value condition = (Value)myConditionEvaluator.evaluate(context); - if (condition == null || !(condition instanceof BooleanValue)) { + Object condition = UnBoxingEvaluator.unbox(myConditionEvaluator.evaluate(context), context); + if (!(condition instanceof BooleanValue)) { throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.boolean.condition.expected")); } return ((BooleanValue)condition).booleanValue()? myThenEvaluator.evaluate(context) : myElseEvaluator.evaluate(context); diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/DoWhileStatementEvaluator.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/DoWhileStatementEvaluator.java index 8d940912ba8e..234e79c87659 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/DoWhileStatementEvaluator.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/DoWhileStatementEvaluator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,7 +41,7 @@ public class DoWhileStatementEvaluator extends LoopEvaluator { while (true) { if (body(context)) break; - value = myConditionEvaluator.evaluate(context); + value = UnBoxingEvaluator.unbox(myConditionEvaluator.evaluate(context), context); if (!(value instanceof BooleanValue)) { throw EvaluateExceptionUtil.BOOLEAN_EXPECTED; } diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/ForStatementEvaluatorBase.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/ForStatementEvaluatorBase.java index 3b1e8cdf43e9..cd5364b409ab 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/ForStatementEvaluatorBase.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/ForStatementEvaluatorBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ public abstract class ForStatementEvaluatorBase extends LoopEvaluator { while (true) { // condition - Object codition = evaluateCondition(context); + Object codition = UnBoxingEvaluator.unbox(evaluateCondition(context), context); if (codition instanceof Boolean) { if (!(Boolean)codition) break; } diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/IfStatementEvaluator.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/IfStatementEvaluator.java index 7d518a0c3591..ed253101d955 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/IfStatementEvaluator.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/IfStatementEvaluator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,7 +41,7 @@ public class IfStatementEvaluator implements Evaluator { } public Object evaluate(EvaluationContextImpl context) throws EvaluateException { - Object value = myConditionEvaluator.evaluate(context); + Object value = UnBoxingEvaluator.unbox(myConditionEvaluator.evaluate(context), context); if(!(value instanceof BooleanValue)) { throw EvaluateExceptionUtil.BOOLEAN_EXPECTED; } else { diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/UnBoxingEvaluator.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/UnBoxingEvaluator.java index 6c6d46257044..8f1f6a7fc3f9 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/UnBoxingEvaluator.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/UnBoxingEvaluator.java @@ -57,18 +57,21 @@ public class UnBoxingEvaluator implements Evaluator{ } public Object evaluate(EvaluationContextImpl context) throws EvaluateException { - final Value result = (Value)myOperand.evaluate(context); - if (result == null) { + return unbox(myOperand.evaluate(context), context); + } + + public static Object unbox(@Nullable Object value, EvaluationContextImpl context) throws EvaluateException { + if (value == null) { throw new EvaluateException("java.lang.NullPointerException: cannot unbox null value"); } - if (result instanceof ObjectReference) { - final String valueTypeName = result.type().name(); + if (value instanceof ObjectReference) { + final String valueTypeName = ((ObjectReference)value).type().name(); final Couple pair = TYPES_TO_CONVERSION_METHOD_MAP.get(valueTypeName); if (pair != null) { - return convertToPrimitive(context, (ObjectReference)result, pair.getFirst(), pair.getSecond()); + return convertToPrimitive(context, (ObjectReference)value, pair.getFirst(), pair.getSecond()); } } - return result; + return value; } @Nullable diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/WhileStatementEvaluator.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/WhileStatementEvaluator.java index b328e55de29c..7a7761544d92 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/WhileStatementEvaluator.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/WhileStatementEvaluator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ public class WhileStatementEvaluator extends LoopEvaluator { public Object evaluate(EvaluationContextImpl context) throws EvaluateException { Object value; while (true) { - value = myConditionEvaluator.evaluate(context); + value = UnBoxingEvaluator.unbox(myConditionEvaluator.evaluate(context), context); if (!(value instanceof BooleanValue)) { throw EvaluateExceptionUtil.BOOLEAN_EXPECTED; } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java index 251d57056fa5..77ab1ccc0672 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import com.intellij.debugger.engine.*; import com.intellij.debugger.engine.evaluation.*; import com.intellij.debugger.engine.evaluation.expression.EvaluatorBuilderImpl; import com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator; +import com.intellij.debugger.engine.evaluation.expression.UnBoxingEvaluator; import com.intellij.debugger.engine.events.SuspendContextCommandImpl; import com.intellij.debugger.jdi.StackFrameProxyImpl; import com.intellij.debugger.jdi.ThreadReferenceProxyImpl; @@ -366,7 +367,7 @@ public abstract class Breakpoint

implements return EvaluatorBuilderImpl.build(getCondition(), contextPsiElement, contextSourcePosition); } }); - final Value value = evaluator.evaluate(context); + Object value = UnBoxingEvaluator.unbox(evaluator.evaluate(context), context); if (!(value instanceof BooleanValue)) { throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.boolean.expected")); }