Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2018-02-01 06:11:39 +0000
committerManoj Palat2018-02-01 06:11:39 +0000
commit98030dde5e7d1a71f5e784a684ebb6042691a0cf (patch)
tree090b02a849d678d774d520aadd27a3933748c6a3
parente5f19832e560b27629028dfbcf7018d21c7254c8 (diff)
downloadeclipse.jdt.core-98030dde5e7d1a71f5e784a684ebb6042691a0cf.tar.gz
eclipse.jdt.core-98030dde5e7d1a71f5e784a684ebb6042691a0cf.tar.xz
eclipse.jdt.core-98030dde5e7d1a71f5e784a684ebb6042691a0cf.zip
Bug 377883 - NPE on open Call Hierarchy
(backport)
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java59
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java7
2 files changed, 65 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java
index d85f74201a..1569fe5215 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java
@@ -7,6 +7,8 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Stephan Herrmann - Contribution for
+ * Bug 377883 - NPE on open Call Hierarchy
*******************************************************************************/
package org.eclipse.jdt.core.tests.model;
@@ -1628,4 +1630,61 @@ public class JavaSearchBugsTests2 extends AbstractJavaSearchTests {
deleteProject("P");
}
}
+ public void testBug401272() throws CoreException, IOException {
+ // the strategy of this test was outlined in https://bugs.eclipse.org/bugs/show_bug.cgi?id=401272#c16
+ try {
+ IJavaProject p = createJavaProject("P", new String[] { "src" }, new String[] { "JCL15_LIB", "/P/libStuff.jar" }, "bin", "1.5");
+
+ org.eclipse.jdt.core.tests.util.Util.createJar(
+ new String[] {
+ // this class must be our possibleMatch #401
+ // it must be binary to trigger the ClassFileMatchLocator
+ // the match must be impossible-due-to-mismatching-type-variables to trigger matchLocator.getMethodBinding(this.pattern);
+ "p2/A.java",
+ "package p2;\n" +
+ "public class A<E> {\n" +
+ " public int test(E b) { return 1; }\n" +
+ " void bar() {\n" +
+ " test(null);\n" +
+ " }\n" +
+ "}\n",
+ // this class contains the method we search for, possibleMatch #402
+ // (must be > 401 possibleMatches to trigger environment cleanup)
+ "p2/B.java",
+ "package p2;\n" +
+ "public class B<T> {\n" +
+ " public int test(T t) {\n" +
+ " return 0;\n" +
+ " }\n" +
+ "}\n"
+ },
+ p.getProject().getLocation().append("libStuff.jar").toOSString(), "1.5");
+ refresh(p);
+
+ createFolder("/P/src/pkg");
+ // 400 matches, which populate MatchLocator.unitScope
+ // all 400 matches are processed in one go of MatchLocator.locateMatches(JavaProject, PossibleMatch[], int, int)
+ // next round will call nameEnvironment.cleanup() but reuse MatchLocator.unitScope ==> BOOM
+ for (int i = 0; i < 400; i++) {
+ createFile("/P/src/pkg/Bug"+i+".java",
+ "package pkg;\n"+
+ "public class Bug"+i+" {\n"+
+ " String[] test(p2.B<String> b) {\n" +
+ " return b.test(\"S\");\n" +
+ " }\n" +
+ "}");
+ }
+
+ waitUntilIndexesReady();
+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { p },
+ IJavaSearchScope.SOURCES|IJavaSearchScope.SYSTEM_LIBRARIES|IJavaSearchScope.APPLICATION_LIBRARIES);
+
+ IMethod method = p.findType("p2.B").getMethods()[1];
+ search(method, METHOD, ALL_OCCURRENCES, scope, this.resultCollector);
+
+ assertSearchResults("libStuff.jar int p2.B.test(T) [No source] EXACT_MATCH"); // an NPE was thrown without the fix
+ } finally {
+ deleteProject("P");
+ }
+ }
}
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java
index 5c0e6ccf11..f084b86fe7 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java
@@ -7,6 +7,8 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Stephan Herrmann - Contribution for
+ * Bug 377883 - NPE on open Call Hierarchy
*******************************************************************************/
package org.eclipse.jdt.internal.core.search.matching;
@@ -1026,8 +1028,10 @@ protected boolean hasAlreadyDefinedType(CompilationUnitDeclaration parsedUnit) {
public void initialize(JavaProject project, int possibleMatchSize) throws JavaModelException {
// clean up name environment only if there are several possible match as it is reused
// when only one possible match (bug 58581)
- if (this.nameEnvironment != null && possibleMatchSize != 1)
+ if (this.nameEnvironment != null && possibleMatchSize != 1) {
this.nameEnvironment.cleanup();
+ this.unitScope = null; // don't leak a reference to the cleaned-up name environment
+ }
SearchableEnvironment searchableEnvironment = project.newSearchableNameEnvironment(this.workingCopies);
@@ -1328,6 +1332,7 @@ public void locateMatches(SearchDocument[] searchDocuments) throws CoreException
this.progressMonitor.done();
if (this.nameEnvironment != null)
this.nameEnvironment.cleanup();
+ this.unitScope = null;
manager.flushZipFiles(this);
this.bindings = null;
}

Back to the top