Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 551345

Summary: [tests] Assert fail with CU presnet in package between tests
Product: [Eclipse Project] JDT Reporter: Kenneth Styrberg <kenneth>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WORKSFORME QA Contact:
Severity: minor    
Priority: P3 CC: rgrunber
Version: 4.13   
Target Milestone: ---   
Hardware: PC   
OS: Windows 10   
See Also: https://git.eclipse.org/r/149949
Whiteboard:

Description Kenneth Styrberg CLA 2019-09-21 16:39:19 EDT
When running refactoring tests i see spuriuous Assert fails in RefactoringTest.createCU(..) when the package still contains an open compilation unit.

Adding a explicit close() call on the CU in RefactoringTest.tryDeletingAllJavaChildren() fixes the problem.


diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RefactoringTest.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RefactoringTest.java
index 10bf8fb..d244e79 100644
--- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RefactoringTest.java
+++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RefactoringTest.java
@@ -66,6 +66,7 @@
 import org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor;
 
 import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil;
+import org.eclipse.jdt.internal.core.CompilationUnit;
 import org.eclipse.jdt.internal.core.manipulation.util.Strings;
 
 import org.eclipse.jdt.ui.tests.refactoring.infra.RefactoringTestPlugin;
@@ -231,10 +232,13 @@
 
 	private static void tryDeletingAllJavaChildren(IPackageFragment pack) throws CoreException {
 		IJavaElement[] kids= pack.getChildren();
-		for (int i= 0; i < kids.length; i++){
-			if (kids[i] instanceof ISourceManipulation){
+		for (int i= 0; i < kids.length; i++) {
+			if (kids[i] instanceof ISourceManipulation) {
 				if (kids[i].exists() && !kids[i].isReadOnly())
 					JavaProjectHelper.delete(kids[i]);
+				if (kids[i] instanceof CompilationUnit) {
+					((CompilationUnit) kids[i]).close();
+				}
 			}
 		}
 	}
Comment 1 Eclipse Genie CLA 2019-09-21 16:42:44 EDT
New Gerrit change created: https://git.eclipse.org/r/149949
Comment 2 Kenneth Styrberg CLA 2019-09-21 16:47:22 EDT
Running locally on windows 10 using Eclipse 2019-09.

Tried with a new workspace with no luck, I suspect some windows update happened since I didn't see this before.
Comment 3 Roland Grunberg CLA 2019-10-31 11:43:12 EDT
I'm unable to reproduce this on Linux running AllRefactoringTests as a JUnit Plugin Test (against a 4.14 I target platform), or in Maven. When you said "no luck", did you mean it's still happening, or that you're no longer able to reproduce. If it still occurs I could try it on a windows box to see.

Are you able to run in Maven and see if you get these errors ? It would be something like :

mvn clean verify -Pbuild-individual-bundles -Dlongnotexistingproperty -f org.eclipse.jdt.ui.tests.refactoring/pom.xml -DtestClass=org.eclipse.jdt.ui.tests.refactoring.AllRefactoringTests

- 'longnotexistingproperty' ensures api-generation isn't run on the bundles, and saves a bit of time in building. (See https://git.eclipse.org/c/platform/eclipse.platform.releng.aggregator.git/tree/eclipse-platform-parent/pom.xml#n850 )
- you could replace AllRefactoringTests with some smaller suite if you happen to know which one is most common for the issue to reproduce
Comment 4 Kenneth Styrberg CLA 2019-10-31 13:48:55 EDT
Hmm, now I can't reproduce either. Must have been som update to Windows or the antivirus that caused the problem.

All seems ok now! Closing as WORKSFORME