From ecab490696a69466bbbb0bf0cec6285dcc4403db Mon Sep 17 00:00:00 2001 From: UNV Date: Thu, 8 May 2025 03:19:03 +0300 Subject: [PATCH] Fixing null-check error from HighlightMethodUtil. --- .../impl/analysis/HighlightMethodUtil.java | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/java-analysis-impl/src/main/java/com/intellij/java/analysis/impl/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java b/java-analysis-impl/src/main/java/com/intellij/java/analysis/impl/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java index 52d90c988..82520ec68 100644 --- a/java-analysis-impl/src/main/java/com/intellij/java/analysis/impl/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java +++ b/java-analysis-impl/src/main/java/com/intellij/java/analysis/impl/codeInsight/daemon/impl/analysis/HighlightMethodUtil.java @@ -515,16 +515,14 @@ public static HighlightInfo.Builder checkMethodCall( hlBuilder = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR) .descriptionAndTooltip(errorMessage) .range(fixRange); - if (hlBuilder != null) { - registerMethodCallIntentions(hlBuilder, methodCall, list, resolveHelper); - registerMethodReturnFixAction(hlBuilder, (MethodCandidateInfo)resolveResult, methodCall); - registerTargetTypeFixesBasedOnApplicabilityInference( - methodCall, - (MethodCandidateInfo)resolveResult, - (PsiMethod)resolved, - hlBuilder - ); - } + registerMethodCallIntentions(hlBuilder, methodCall, list, resolveHelper); + registerMethodReturnFixAction(hlBuilder, (MethodCandidateInfo)resolveResult, methodCall); + registerTargetTypeFixesBasedOnApplicabilityInference( + methodCall, + (MethodCandidateInfo)resolveResult, + (PsiMethod)resolved, + hlBuilder + ); } } } @@ -559,18 +557,16 @@ else if (candidateInfo != null && !candidateInfo.isApplicable()) { toolTip = description; } PsiElement element = elementToHighlight.get(); - int navigationShift = - element instanceof PsiExpressionList ? +1 : 0; // argument list starts with paren which there is no need to highlight + // argument list starts with paren which there is no need to highlight + int navigationShift = element instanceof PsiExpressionList ? +1 : 0; hlBuilder = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR) .range(element) .description(description) .escapedToolTip(toolTip) .navigationShift(navigationShift); - if (hlBuilder != null) { - registerMethodCallIntentions(hlBuilder, methodCall, list, resolveHelper); - registerMethodReturnFixAction(hlBuilder, candidateInfo, methodCall); - registerTargetTypeFixesBasedOnApplicabilityInference(methodCall, candidateInfo, resolvedMethod, hlBuilder); - } + registerMethodCallIntentions(hlBuilder, methodCall, list, resolveHelper); + registerMethodReturnFixAction(hlBuilder, candidateInfo, methodCall); + registerTargetTypeFixesBasedOnApplicabilityInference(methodCall, candidateInfo, resolvedMethod, hlBuilder); } else { PsiReferenceExpression methodExpression = methodCall.getMethodExpression(); @@ -2305,7 +2301,7 @@ private static void registerChangeMethodSignatureFromUsageIntentions( @Nonnull JavaResolveResult[] candidates, @Nonnull PsiExpressionList list, @Nullable HighlightInfo.Builder highlightInfo, - TextRange fixRange + @Nullable TextRange fixRange ) { if (candidates.length == 0) { return; @@ -2318,19 +2314,19 @@ private static void registerChangeMethodSignatureFromUsageIntentions( private static void registerChangeMethodSignatureFromUsageIntention( @Nonnull PsiExpression[] expressions, - @Nullable HighlightInfo.Builder highlightInfo, - TextRange fixRange, + @Nullable HighlightInfo.Builder hlBuilder, + @Nullable TextRange fixRange, @Nonnull JavaResolveResult candidate, @Nonnull PsiElement context ) { - if (highlightInfo == null || !candidate.isStaticsScopeCorrect()) { + if (hlBuilder == null || !candidate.isStaticsScopeCorrect()) { return; } PsiMethod method = (PsiMethod)candidate.getElement(); PsiSubstitutor substitutor = candidate.getSubstitutor(); if (method != null && context.getManager().isInProject(method)) { QuickFixFactory factory = QuickFixFactory.getInstance(); - highlightInfo.registerFix( + hlBuilder.registerFix( factory.createChangeMethodSignatureFromUsageFix( method, expressions, @@ -2339,9 +2335,12 @@ private static void registerChangeMethodSignatureFromUsageIntention( false, 2 ), - fixRange + null, + null, + fixRange, + null ); - highlightInfo.registerFix( + hlBuilder.registerFix( factory.createChangeMethodSignatureFromUsageReverseOrderFix( method, expressions, @@ -2350,7 +2349,10 @@ private static void registerChangeMethodSignatureFromUsageIntention( false, 2 ), - fixRange + null, + null, + fixRange, + null ); } }