Skip to content

Commit

Permalink
stress test for catastrophic "whole file is yellow" condition
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 425b5bcacdca494d242e731d0bcf492be8c71eb8
  • Loading branch information
cdracm authored and intellij-monorepo-bot committed Jul 21, 2021
1 parent 0c5f5ae commit fe8ee93
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 23 deletions.
38 changes: 17 additions & 21 deletions java/java-tests/testData/psi/resolve/Thinlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ else if ("desktop" == classname) {
*
*/
private int[][] getGrid(Object component, int gap) {
java.lang.ref.Reference.reachabilityFence(gap);
int count = 0;
for (Object comp = get(component, "component"); comp != null;
comp = get(comp, ":next")) {
Expand Down Expand Up @@ -1105,6 +1106,7 @@ private int getSum(int[] values,
*/
private Dimension getFieldSize(Object component) {
String text = getString(component, "text", "");
java.lang.ref.Reference.reachabilityFence(text);
int columns = getInteger(component, "columns", 0);
FontMetrics fm = getFontMetrics(getFont());
return new Dimension(((columns > 0) ?
Expand All @@ -1117,6 +1119,7 @@ private Dimension getFieldSize(Object component) {
*/
private Dimension getSize(Object component,
int dx, int dy, String defaultalignment) {
java.lang.ref.Reference.reachabilityFence(defaultalignment);
String text = getString(component, "text", null);
int tw = 0;
int th = 0;
Expand Down Expand Up @@ -1856,6 +1859,8 @@ private void paintField(Graphics g,
int clipx, int clipy, int clipwidth, int clipheight, Object component,
int width, int height, boolean inside, boolean pressed,
boolean focus, boolean enabled, boolean hidden, int left) {
java.lang.ref.Reference.reachabilityFence(inside);
java.lang.ref.Reference.reachabilityFence(pressed);
boolean editable = getBoolean(component, "editable", true);
paintRect(g, 0, 0, width, height, enabled ? c_border : c_disable,
editable ? c_textbg : c_bg, true, true, true, true);
Expand Down Expand Up @@ -3616,6 +3621,7 @@ else if (("list" == classname) ||
!popuptrigger) { // e.getClickCount()
Rectangle view = getRectangle(component, ":view");
Rectangle viewport = getRectangle(component, ":port");
java.lang.ref.Reference.reachabilityFence(viewport);
int my = mousey + view.y - referencey;
String itemname = ("list" == classname) ? "item" :
(("table" == classname) ? "row" : "node");
Expand Down Expand Up @@ -3822,6 +3828,7 @@ private Object getNextItem(Object component,
private void processField(int x, int y, int clickcount,
int id, Object component,
Object part, boolean multiline, boolean hidden, int left) {
java.lang.ref.Reference.reachabilityFence(part);
if (id == MouseEvent.MOUSE_PRESSED) {
setReference(component, 2 + left, 2);
int mx = x - referencex;
Expand Down Expand Up @@ -4239,6 +4246,7 @@ else if ("popupmenu" == classname) {
*/
private boolean findScrollPane(Object component,
int x, int y, Rectangle bounds) {
java.lang.ref.Reference.reachabilityFence(bounds);
Rectangle port = getRectangle(component, ":port");
if ((x < port.x) || (y < port.y) ||
((x >= port.x + port.width) && (y >= port.y + port.height))) {
Expand Down Expand Up @@ -4763,9 +4771,9 @@ public void add(Object parent, Object component, int index) {
/**
*
*/
private void addItem(Object parent, Object key, Object component) {
insertItem(parent, key, component, -1);
}
//private void addItem(Object parent, Object key, Object component) {
// insertItem(parent, key, component, -1);
//}

/**
*
Expand Down Expand Up @@ -4989,12 +4997,15 @@ protected void parseXML(InputStream inputstream) throws Exception {
*
*/
protected void startElement(String name, Hashtable attributelist) {
java.lang.ref.Reference.reachabilityFence(name);
java.lang.ref.Reference.reachabilityFence(attributelist);
}

/**
*
*/
protected void characters(String text) {
java.lang.ref.Reference.reachabilityFence(text);
}

/**
Expand Down Expand Up @@ -5214,13 +5225,6 @@ else if (entity.startsWith("#")) {
throw new IllegalArgumentException();
}

/**
* Convert entities.
*/
private static String convert(StringBuffer text) {
return null;
}

/*private InputStream inputreader;
private byte[] data;
private int inputfrom = 0, inputto = 0;
Expand Down Expand Up @@ -5576,7 +5580,8 @@ else if (("paint" == mode) && ("tabbedpane" == classname)) {
*/
private boolean setString(Object component,
String key, String value, String defaultvalue) {
/*boolean changed = set(component, key, value);
java.lang.ref.Reference.reachabilityFence(defaultvalue);
boolean changed = set(component, key, value);
if (changed && ("name" == key)) {
//for (Class cls = getClass(); cls != null; cls = cls.getSuperclass()) {
Field[] fields = getClass().getDeclaredFields();
Expand All @@ -5594,8 +5599,7 @@ private boolean setString(Object component,
getClass().getField(value).set(this, component);
} catch (Exception exc) {}
}
return changed;*/
return set(component, key, value);
return changed;
}

/**
Expand Down Expand Up @@ -5623,14 +5627,6 @@ private boolean setChoice(Object component,
throw new IllegalArgumentException("unknown " + value + " for " + key);
}

/**
*
*/
private boolean setIcon(Object component,
String key, String path, Image defaultvalue) {
return set(component, key, (path != null) ? getIcon(path) : defaultvalue);
}

/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.intellij.codeInspection.accessStaticViaInstance.AccessStaticViaInstance;
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.codeInspection.ex.InspectionToolRegistrar;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
Expand Down Expand Up @@ -79,12 +80,16 @@
import com.intellij.openapi.project.DumbServiceImpl;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.ProperTextRange;
import com.intellij.openapi.util.Segment;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.profile.codeInspection.InspectionProfileManager;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
Expand Down Expand Up @@ -1488,7 +1493,7 @@ public void testCancelsItSelfOnTypingInAlienProject() throws Throwable {

public void testPasteInAnonymousCodeBlock() {
configureByText(JavaFileType.INSTANCE, "class X{ void f() {" +
" int x=0;\n" +
" int x=0;x++;\n" +
" Runnable r = new Runnable() { public void run() {\n" +
" <caret>\n" +
" }};\n" +
Expand All @@ -1500,7 +1505,7 @@ public void testPasteInAnonymousCodeBlock() {
getEditor().getSelectionModel().removeSelection();
PlatformTestUtil.invokeNamedAction(IdeActions.ACTION_EDITOR_PASTE);
List<HighlightInfo> errors = highlightErrors();
assertEquals(1, errors.size());
assertEquals(getEditor().getDocument().getText(), 1, errors.size());
}

public void testPostHighlightingPassRunsOnEveryPsiModification() throws Exception {
Expand Down Expand Up @@ -1641,6 +1646,66 @@ public void testInterruptOnTyping() throws Throwable {
fail("PCE must have been thrown");
}

@Override
protected Sdk getTestProjectJdk() {
return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
}

@Override
protected @NotNull LanguageLevel getProjectLanguageLevel() {
return LanguageLevel.JDK_11;
}

public void testTypingInsideCodeBlockDoesntLeadToCatastrophicUnusedEverything_Stress() throws Throwable {
InspectionProfileImpl profile = InspectionProfileManager.getInstance(getProject()).getCurrentProfile();
profile.disableAllTools(getProject());
@NonNls String filePath = "/psi/resolve/Thinlet.java";
configureByFile(filePath);

PsiDocumentManager.getInstance(myProject).commitAllDocuments();

PsiFile file = getFile();
Project project = file.getProject();
CodeInsightTestFixtureImpl.ensureIndexesUpToDate(project);
List<HighlightInfo> errors = doHighlighting(HighlightSeverity.ERROR);
assertEmpty(errors);
List<HighlightInfo> initialWarnings = doHighlighting(HighlightSeverity.WARNING);
assertEmpty(initialWarnings);
int N_BLOCKS = codeBlocks(file).size();
assertTrue("codeblocks :"+N_BLOCKS, N_BLOCKS > 1000);
Random random = new Random();
int N = 50;
// try with both serialized and not-serialized passes
myDaemonCodeAnalyzer.serializeCodeInsightPasses(false);
for (int i=0; i<N*2; i++) {
PsiCodeBlock block = codeBlocks(file).get(random.nextInt(N_BLOCKS));
getEditor().getCaretModel().moveToOffset(block.getLBrace().getTextOffset() + 1);
type("\n/*xxx*/");
List<HighlightInfo> warnings = doHighlighting(HighlightSeverity.WARNING);
if (!warnings.isEmpty()) {
System.out.println("\n-----\n"+getEditor().getDocument().getText()+"\n--------\n");
}
assertEmpty(warnings);
if (i == N) {
// repeat the same steps with serialized passes
myDaemonCodeAnalyzer.serializeCodeInsightPasses(true);
}
}
}

@NotNull
private List<PsiCodeBlock> codeBlocks(@NotNull PsiFile file) {
List<PsiCodeBlock> blocks = new ArrayList<>();
file.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitCodeBlock(PsiCodeBlock block) {
blocks.add(block);
super.visitCodeBlock(block);
}
});
return blocks;
}

public void testCodeFoldingInSplittedWindowAppliesToAllEditors() {
Set<Editor> applied = ConcurrentCollectionFactory.createConcurrentSet(HashingStrategy.canonical());
Set<Editor> collected = ConcurrentCollectionFactory.createConcurrentSet(HashingStrategy.canonical());
Expand Down

0 comments on commit fe8ee93

Please sign in to comment.