From 4cbb22cb80d29f8ab9ac838aedd7b6ade9bec073 Mon Sep 17 00:00:00 2001 From: Nikita Eshkeev Date: Mon, 22 Mar 2021 15:14:41 +0300 Subject: [PATCH] [EA-260251] IAE: Internals.checkLength: fixes after review This patch fixes the logging so no users' code is leaked due to the logger. The logger prints the information about the method's class (whether or not it's PsiMethodImpl) and adds the method's throws list as an attachment. GitOrigin-RevId: 5bb243e1922ab729ba2077bb32969ff7a521c87f --- ...ndantThrowsDeclarationLocalInspection.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/unneededThrows/RedundantThrowsDeclarationLocalInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/unneededThrows/RedundantThrowsDeclarationLocalInspection.java index 83d241178a13..7314494b8cd0 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/unneededThrows/RedundantThrowsDeclarationLocalInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/unneededThrows/RedundantThrowsDeclarationLocalInspection.java @@ -12,6 +12,8 @@ import com.intellij.codeInspection.util.IntentionFamilyName; import com.intellij.codeInspection.util.IntentionName; import com.intellij.java.analysis.JavaAnalysisBundle; import com.intellij.lang.jvm.JvmModifier; +import com.intellij.openapi.diagnostic.Attachment; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; @@ -32,14 +34,13 @@ import org.jetbrains.annotations.*; import java.util.*; import java.util.function.Predicate; -import java.util.logging.Logger; import java.util.stream.Stream; import static com.intellij.psi.PsiModifier.ABSTRACT; @SuppressWarnings("InspectionDescriptionNotFoundInspection") // delegates public final class RedundantThrowsDeclarationLocalInspection extends AbstractBaseJavaLocalInspectionTool { - private static final Logger LOGGER = Logger.getLogger(RedundantThrowsDeclarationLocalInspection.class.getName()); + private static final Logger LOGGER = Logger.getInstance(RedundantThrowsDeclarationLocalInspection.class.getName()); @NotNull private final RedundantThrowsDeclarationInspection myGlobalTool; @@ -99,8 +100,10 @@ public final class RedundantThrowsDeclarationLocalInspection extends AbstractBas final PsiClassType[] referencedTypes = throwsList.getReferencedTypes(); if (referenceElements.length != referencedTypes.length) { - LOGGER.warning("Stub-PSI inconsistency detected. The number of elements in the throws list doesn't match the number of types in the throws list:"); - LOGGER.warning(method.getText()); + LOGGER.error("Stub-PSI inconsistency detected. " + + "The number of elements in the throws list doesn't match the number of types in the throws list. " + + "The method's class is " + method.getClass().getSimpleName(), + new Attachment("throwsList.sourcePsi.txt", throwsList.isValid() ? throwsList.getText() : "")); } final PsiElementFactory factory = JavaPsiFacade.getElementFactory(method.getProject()); @@ -247,15 +250,19 @@ public final class RedundantThrowsDeclarationLocalInspection extends AbstractBas * @return the set of throws declarations as strings from the throws list excluding the currently eliminated throws declaration */ private static List getThrowsListWithoutCurrent(@NotNull final PsiReferenceList throwsList, - @NotNull final PsiJavaCodeReferenceElement currentRef) { - + @NotNull final PsiJavaCodeReferenceElement currentRef) { final PsiJavaCodeReferenceElement[] referenceElements = throwsList.getReferenceElements(); final PsiClassType[] referencedTypes = throwsList.getReferencedTypes(); if (referenceElements.length != referencedTypes.length) { - LOGGER.warning("Stub-PSI inconsistency detected. The number of elements in the throws list doesn't match the number of types in the throws list:"); - LOGGER.warning(String.valueOf(PsiTreeUtil.getParentOfType(throwsList, PsiMethod.class))); + final PsiMethod method = PsiTreeUtil.getParentOfType(throwsList, PsiMethod.class); + final String methodClass = method != null ? method.getClass().getSimpleName() : "null"; + + LOGGER.error("Stub-PSI inconsistency detected. " + + "The number of elements in the throws list doesn't match the number of types in the throws list. " + + "The method's class is " + methodClass, + new Attachment("throwsList.sourcePsi.txt", throwsList.isValid() ? throwsList.getText() : "")); } final PsiElementFactory factory = JavaPsiFacade.getElementFactory(throwsList.getProject());