diff --git a/java/java-impl/src/com/intellij/refactoring/extractMethodObject/ExtractLightMethodObjectHandler.java b/java/java-impl/src/com/intellij/refactoring/extractMethodObject/ExtractLightMethodObjectHandler.java index 746d27d9ee88..4b4f0f308451 100644 --- a/java/java-impl/src/com/intellij/refactoring/extractMethodObject/ExtractLightMethodObjectHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/extractMethodObject/ExtractLightMethodObjectHandler.java @@ -127,8 +127,11 @@ public class ExtractLightMethodObjectHandler { // expand lambda to code block if needed PsiElement containingMethod = PsiTreeUtil.getParentOfType(originalAnchor, PsiMember.class, PsiLambdaExpression.class); if (containingMethod instanceof PsiLambdaExpression) { - PsiCodeBlock newBody = RefactoringUtil.expandExpressionLambdaToCodeBlock((PsiLambdaExpression)containingMethod); - originalAnchor = newBody.getStatements()[0]; + PsiLambdaExpression lambdaExpression = (PsiLambdaExpression)containingMethod; + if (lambdaExpression.getBody() instanceof PsiExpression) { + PsiCodeBlock newBody = RefactoringUtil.expandExpressionLambdaToCodeBlock(lambdaExpression); + originalAnchor = newBody.getStatements()[0]; + } } PsiElement anchor = RefactoringUtil.getParentStatement(originalAnchor, false);