Skip to content

Commit 0ffbaeb

Browse files
amaembointellij-monorepo-bot
authored andcommitted
IDEA-383075 [java-psi] Huge CPU usage after opening a Java class with wildcard generics in a method
GitOrigin-RevId: ed56ac24ce9e113a36e00ffeea765cd68d756d72
1 parent fc860a6 commit 0ffbaeb

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

java/java-psi-impl/src/com/intellij/psi/impl/cache/ExplicitTypeAnnotationContainer.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ public void accept(@NotNull PsiElementVisitor visitor) {
340340
private class TypeAnnotationContainerProvider implements TypeAnnotationProvider {
341341
private final PsiElement myParent;
342342
private final @Nullable PsiAnnotationOwner myOwner;
343+
private final NotNullLazyValue<PsiAnnotation[]> myAnnotations = NotNullLazyValue.createValue(this::computeAnnotations);
343344

344345
private TypeAnnotationContainerProvider(PsiElement parent, @Nullable PsiAnnotationOwner owner) {
345346
myParent = parent;
@@ -351,8 +352,7 @@ private TypeAnnotationContainerProvider(PsiElement parent, @Nullable PsiAnnotati
351352
return new TypeAnnotationContainerProvider(myParent, owner);
352353
}
353354

354-
@Override
355-
public @NotNull PsiAnnotation @NotNull [] getAnnotations() {
355+
private @NotNull PsiAnnotation @NotNull [] computeAnnotations() {
356356
List<PsiAnnotation> result = new ArrayList<>();
357357
for (TypeAnnotationEntry entry : myList) {
358358
if (entry.myPath.length == 0) {
@@ -363,5 +363,10 @@ private TypeAnnotationContainerProvider(PsiElement parent, @Nullable PsiAnnotati
363363
}
364364
return result.toArray(PsiAnnotation.EMPTY_ARRAY);
365365
}
366+
367+
@Override
368+
public @NotNull PsiAnnotation @NotNull [] getAnnotations() {
369+
return myAnnotations.getValue();
370+
}
366371
}
367372
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
package com.intellij.java.codeInsight.daemon.lambda;
3+
4+
import com.intellij.idea.TestFor;
5+
import com.intellij.testFramework.IdeaTestUtil;
6+
import com.intellij.testFramework.LightProjectDescriptor;
7+
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
8+
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
9+
import org.jetbrains.annotations.NotNull;
10+
11+
import java.util.List;
12+
13+
public final class LightGuavaNullabilityHighlightingTest extends LightJavaCodeInsightFixtureTestCase {
14+
private static final LightProjectDescriptor DESCRIPTOR =
15+
new DefaultLightProjectDescriptor(IdeaTestUtil::getMockJdk21, List.of("com.google.guava:guava:33.5.0-jre"));
16+
17+
@Override
18+
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
19+
return DESCRIPTOR;
20+
}
21+
22+
@TestFor(issues = "IDEA-383075")
23+
public void testHighlightWithAnnotatedUpperBound() {
24+
myFixture.configureByText("Test.java", """
25+
import com.google.common.collect.Multimap;
26+
27+
class Test {
28+
public interface InvocationOnMock {}
29+
30+
public interface Answer<T> {
31+
T answer(InvocationOnMock invocation) throws Throwable;
32+
}
33+
34+
private native Multimap<?, String> onInterceptedDaoCallReturningMultimap(InvocationOnMock invocation);
35+
public static native Object doAnswer(Answer answer);
36+
37+
public void prepareMocks() {
38+
doAnswer(this::onInterceptedDaoCallReturningMultimap);
39+
}
40+
}""");
41+
myFixture.checkHighlighting();
42+
}
43+
}

0 commit comments

Comments
 (0)