Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 99507 Details for
Bug 229951
StackOverflowError during JavaSearchScope.add for large workspace
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix and regression tests
229951.txt (text/plain), 12.86 KB, created by
Jerome Lanneluc
on 2008-05-09 12:49:03 EDT
(
hide
)
Description:
Proposed fix and regression tests
Filename:
MIME Type:
Creator:
Jerome Lanneluc
Created:
2008-05-09 12:49:03 EDT
Size:
12.86 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/model/JavaSearchMultipleProjectsTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchMultipleProjectsTests.java,v >retrieving revision 1.49 >diff -u -r1.49 JavaSearchMultipleProjectsTests.java >--- src/org/eclipse/jdt/core/tests/model/JavaSearchMultipleProjectsTests.java 7 May 2008 11:06:18 -0000 1.49 >+++ src/org/eclipse/jdt/core/tests/model/JavaSearchMultipleProjectsTests.java 9 May 2008 16:48:17 -0000 >@@ -1336,4 +1336,97 @@ > } > } > >+/** >+ * @bug 229951: StackOverflowError during JavaSearchScope.add for large workspace >+ * @test Ensure that no StackOverFlowError occurs when searching in a project referencing a cycle >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=229951" >+ */ >+public void testBug229951a() throws Exception { >+ try { >+ createJavaProject("P1"); >+ createFile("/P1/test.jar", ""); >+ editFile( >+ "/P1/.classpath", >+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + >+ "<classpath>\n" + >+ " <classpathentry kind=\"lib\" path=\"test.jar\"/>\n" + >+ " <classpathentry exported=\"true\" kind=\"src\" path=\"/P2\"/>\n" + >+ " <classpathentry kind=\"output\" path=\"bin\"/>\n" + >+ "</classpath>" >+ ); >+ createJavaProject("P2"); >+ createFile("/P2/test.jar", ""); >+ editFile( >+ "/P2/.classpath", >+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + >+ "<classpath>\n" + >+ " <classpathentry kind=\"lib\" path=\"test.jar\"/>\n" + >+ " <classpathentry exported=\"true\" kind=\"src\" path=\"/P1\"/>\n" + >+ " <classpathentry kind=\"output\" path=\"bin\"/>\n" + >+ "</classpath>" >+ ); >+ createJavaProject("P3", new String[] {""}, new String[] {"JCL_LIB"}, new String[] {"/P2"}, ""); >+ createFile( >+ "/P3/X229951.java", >+ "public class X229951 {\n" + >+ "}" >+ ); >+ IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); >+ JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); >+ search("X229951", TYPE, DECLARATIONS, scope, resultCollector); >+ assertSearchResults( >+ "Unexpected references of annotation type MyAnnot", >+ "X229951.java X229951 [X229951]", >+ resultCollector); >+ } finally { >+ deleteProjects(new String[] {"P1", "P2", "P3"}); >+ } >+} >+ >+/** >+ * @bug 229951: StackOverflowError during JavaSearchScope.add for large workspace >+ * @test Ensure that no StackOverFlowError occurs when creating a search scope on a project referencing a cycle >+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=229951" >+ */ >+public void testBug229951b() throws Exception { >+ try { >+ createJavaProject("P1"); >+ createFile("/P1/test.jar", ""); >+ editFile( >+ "/P1/.classpath", >+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + >+ "<classpath>\n" + >+ " <classpathentry kind=\"lib\" path=\"test.jar\"/>\n" + >+ " <classpathentry exported=\"true\" kind=\"src\" path=\"/P2\"/>\n" + >+ " <classpathentry kind=\"output\" path=\"bin\"/>\n" + >+ "</classpath>" >+ ); >+ createJavaProject("P2"); >+ createFile("/P2/test.jar", ""); >+ editFile( >+ "/P2/.classpath", >+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + >+ "<classpath>\n" + >+ " <classpathentry kind=\"lib\" path=\"test.jar\"/>\n" + >+ " <classpathentry exported=\"true\" kind=\"src\" path=\"/P1\"/>\n" + >+ " <classpathentry kind=\"output\" path=\"bin\"/>\n" + >+ "</classpath>" >+ ); >+ IJavaProject p3 = createJavaProject("P3", new String[] {""}, new String[] {"JCL_LIB"}, new String[] {"/P2"}, ""); >+ createFile( >+ "/P3/X229951.java", >+ "public class X229951 {\n" + >+ "}" >+ ); >+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {p3}); >+ assertScopeEquals( >+ "JavaSearchScope on [\n" + >+ " /P3\n" + >+ " " + getExternalJCLPathString() + "\n" + >+ "]", >+ scope); >+ } finally { >+ deleteProjects(new String[] {"P1", "P2", "P3"}); >+ } >+} > } >Index: src/org/eclipse/jdt/core/tests/model/JavaSearchScopeTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchScopeTests.java,v >retrieving revision 1.15 >diff -u -r1.15 JavaSearchScopeTests.java >--- src/org/eclipse/jdt/core/tests/model/JavaSearchScopeTests.java 6 Mar 2008 14:24:03 -0000 1.15 >+++ src/org/eclipse/jdt/core/tests/model/JavaSearchScopeTests.java 9 May 2008 16:48:18 -0000 >@@ -50,13 +50,6 @@ > > super.tearDown(); > } >-protected void assertScopeEquals(String expected, IJavaSearchScope scope) { >- String actual = scope.toString(); >- if (!expected.equals(actual)) { >- System.out.println(displayString(actual, 3) + ","); >- } >- assertEquals("Unexpected scope", expected, actual); >-} > /* > * Ensures that a Java search scope with SOURCES only is correct. > */ >Index: src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java,v >retrieving revision 1.212 >diff -u -r1.212 AbstractJavaModelTests.java >--- src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 7 May 2008 11:06:18 -0000 1.212 >+++ src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 9 May 2008 16:48:15 -0000 >@@ -267,6 +267,13 @@ > actual > ); > } >+ protected void assertScopeEquals(String expected, IJavaSearchScope scope) { >+ String actual = scope.toString(); >+ if (!expected.equals(actual)) { >+ System.out.println(displayString(actual, 3) + ","); >+ } >+ assertEquals("Unexpected scope", expected, actual); >+ } > protected void addClasspathEntry(IJavaProject project, IClasspathEntry entry) throws JavaModelException{ > IClasspathEntry[] entries = project.getRawClasspath(); > int length = entries.length; >#P org.eclipse.jdt.core >Index: model/org/eclipse/jdt/internal/core/SearchableEnvironment.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SearchableEnvironment.java,v >retrieving revision 1.70 >diff -u -r1.70 SearchableEnvironment.java >--- model/org/eclipse/jdt/internal/core/SearchableEnvironment.java 2 Oct 2007 17:12:02 -0000 1.70 >+++ model/org/eclipse/jdt/internal/core/SearchableEnvironment.java 9 May 2008 16:48:22 -0000 >@@ -51,13 +51,6 @@ > || !JavaCore.IGNORE.equals(project.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true)); > this.workingCopies = workingCopies; > this.nameLookup = project.newNameLookup(workingCopies); >- >- // Create search scope with visible entry on the project's classpath >- if(this.checkAccessRestrictions) { >- this.searchScope = BasicSearchEngine.createJavaSearchScope(new IJavaElement[] {project}); >- } else { >- this.searchScope = BasicSearchEngine.createJavaSearchScope(this.nameLookup.packageFragmentRoots); >- } > } > > /** >@@ -225,7 +218,7 @@ > name, > SearchPattern.R_EXACT_MATCH, > searchFor, >- this.searchScope, >+ getSearchScope(), > typeRequestor, > CANCEL_IF_NOT_READY_TO_SEARCH, > progressMonitor); >@@ -387,7 +380,7 @@ > simpleName, > matchRule, // not case sensitive > searchFor, >- this.searchScope, >+ getSearchScope(), > typeRequestor, > CANCEL_IF_NOT_READY_TO_SEARCH, > progressMonitor); >@@ -432,6 +425,18 @@ > } > } > >+ private IJavaSearchScope getSearchScope() { >+ if (this.searchScope == null) { >+ // Create search scope with visible entry on the project's classpath >+ if(this.checkAccessRestrictions) { >+ this.searchScope = BasicSearchEngine.createJavaSearchScope(new IJavaElement[] {project}); >+ } else { >+ this.searchScope = BasicSearchEngine.createJavaSearchScope(this.nameLookup.packageFragmentRoots); >+ } >+ } >+ return this.searchScope; >+ } >+ > /** > * @see org.eclipse.jdt.internal.compiler.env.INameEnvironment#isPackage(char[][], char[]) > */ >Index: search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java,v >retrieving revision 1.53 >diff -u -r1.53 BasicSearchEngine.java >--- search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java 26 Feb 2008 10:11:47 -0000 1.53 >+++ search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java 9 May 2008 16:48:25 -0000 >@@ -129,14 +129,20 @@ > * @see SearchEngine#createJavaSearchScope(IJavaElement[], int) for detailed comment. > */ > public static IJavaSearchScope createJavaSearchScope(IJavaElement[] elements, int includeMask) { >+ HashSet projectsToBeAdded = new HashSet(2); >+ for (int i = 0, length = elements.length; i < length; i++) { >+ IJavaElement element = elements[i]; >+ if (element instanceof JavaProject) { >+ projectsToBeAdded.add(element); >+ } >+ } > JavaSearchScope scope = new JavaSearchScope(); >- HashSet visitedProjects = new HashSet(2); > for (int i = 0, length = elements.length; i < length; i++) { > IJavaElement element = elements[i]; > if (element != null) { > try { >- if (element instanceof JavaProject) { >- scope.add((JavaProject)element, includeMask, visitedProjects); >+ if (projectsToBeAdded.remove(element)) { >+ scope.add((JavaProject)element, includeMask, projectsToBeAdded); > } else { > scope.add(element); > } >Index: search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java,v >retrieving revision 1.69 >diff -u -r1.69 JavaSearchScope.java >--- search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java 25 Apr 2008 13:20:45 -0000 1.69 >+++ search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java 9 May 2008 16:48:25 -0000 >@@ -92,8 +92,8 @@ > * Add java project all fragment roots to current java search scope. > * @see #add(JavaProject, IPath, int, HashSet, IClasspathEntry) > */ >-public void add(JavaProject project, int includeMask, HashSet visitedProject) throws JavaModelException { >- add(project, null, includeMask, visitedProject, null); >+public void add(JavaProject project, int includeMask, HashSet projectsToBeAdded) throws JavaModelException { >+ add(project, null, includeMask, projectsToBeAdded, null); > } > /** > * Add a path to current java search scope or all project fragment roots if null. >@@ -102,13 +102,13 @@ > * @param javaProject Project used to get resolved classpath entries > * @param pathToAdd Path to add in case of single element or null if user want to add all project package fragment roots > * @param includeMask Mask to apply on classpath entries >- * @param visitedProjects Set to avoid infinite recursion >+ * @param projectsToBeAdded Set to avoid infinite recursion > * @param referringEntry Project raw entry in referring project classpath > * @throws JavaModelException May happen while getting java model info > */ >-void add(JavaProject javaProject, IPath pathToAdd, int includeMask, HashSet visitedProjects, IClasspathEntry referringEntry) throws JavaModelException { >+void add(JavaProject javaProject, IPath pathToAdd, int includeMask, HashSet projectsToBeAdded, IClasspathEntry referringEntry) throws JavaModelException { > IProject project = javaProject.getProject(); >- if (!project.isAccessible() || !visitedProjects.add(project)) return; >+ if (!project.isAccessible() || projectsToBeAdded.contains(project)) return; > > IPath projectPath = project.getFullPath(); > String projectPathString = projectPath.toString(); >@@ -125,10 +125,6 @@ > // Add only exported entries. > // Source folder are implicitly exported. > if (!entry.isExported() && entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) { >- // Need to remove the project from visited projects list to be sure >- // not to skip library when the project will be added as a top level. >- // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=176831 >- visitedProjects.remove(project); > continue; > } > cpEntry = cpEntry.combineWith((ClasspathEntry)referringEntry); >@@ -188,7 +184,9 @@ > if ((includeMask & REFERENCED_PROJECTS) != 0) { > IPath path = entry.getPath(); > if (pathToAdd == null || pathToAdd.equals(path)) { >- add((JavaProject) model.getJavaProject(path.lastSegment()), null, includeMask, visitedProjects, cpEntry); >+ projectsToBeAdded.add(project); // avoid infinite recursion >+ add((JavaProject) model.getJavaProject(path.lastSegment()), null, includeMask, projectsToBeAdded, cpEntry); >+ projectsToBeAdded.remove(project); > } > } > break;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 229951
:
99464
|
99483
| 99507