Fix KNPE in introduce when expression (EA-118718)

This commit is contained in:
Andrey Uskov
2018-12-24 19:42:28 +03:00
parent 69613d25f0
commit bc71a7605a
3 changed files with 4 additions and 4 deletions
@@ -98,8 +98,8 @@ private fun KtExpression?.getWhenConditionSubjectCandidate(): KtExpression? {
} }
} }
fun KtWhenExpression.introduceSubject(): KtWhenExpression { fun KtWhenExpression.introduceSubject(): KtWhenExpression? {
val subject = getSubjectToIntroduce()!! val subject = getSubjectToIntroduce() ?: return null
val commentSaver = CommentSaver(this, saveLineBreaks = true) val commentSaver = CommentSaver(this, saveLineBreaks = true)
@@ -192,7 +192,7 @@ class IfToWhenIntention : SelfTargetingRangeIntention<KtIfExpression>(KtIfExpres
if (whenExpression.getSubjectToIntroduce() != null) { if (whenExpression.getSubjectToIntroduce() != null) {
whenExpression = whenExpression.introduceSubject() whenExpression = whenExpression.introduceSubject() ?: return
} }
val result = ifExpression.replaced(whenExpression) val result = ifExpression.replaced(whenExpression)
@@ -334,7 +334,7 @@ private fun makeCall(
val inlinableCall = controlFlow.outputValues.size <= 1 val inlinableCall = controlFlow.outputValues.size <= 1
val unboxingExpressions = val unboxingExpressions =
if (inlinableCall) { if (inlinableCall) {
controlFlow.outputValueBoxer.getUnboxingExpressions(callText!!) controlFlow.outputValueBoxer.getUnboxingExpressions(callText ?: return)
} }
else { else {
val varNameValidator = NewDeclarationNameValidator(block, anchorInBlock, NewDeclarationNameValidator.Target.VARIABLES) val varNameValidator = NewDeclarationNameValidator(block, anchorInBlock, NewDeclarationNameValidator.Target.VARIABLES)