Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2014-02-10 07:14:34 +0000
committerssankaran2014-02-10 07:14:34 +0000
commit5981e91cc71ba86df42ff9d60654ccdd89adffe1 (patch)
tree95d57cf6d6d256fb93a73fa32aa27c9b25766de5
parent316430f6a7a386142798774df034be0e36155d28 (diff)
downloadeclipse.jdt.core-5981e91cc71ba86df42ff9d60654ccdd89adffe1.tar.gz
eclipse.jdt.core-5981e91cc71ba86df42ff9d60654ccdd89adffe1.tar.xz
eclipse.jdt.core-5981e91cc71ba86df42ff9d60654ccdd89adffe1.zip
Fixed Bug 427677 - [1.8][search] NPE in MatchLocator.reportMatching with
unresolved NameQualifiedType qualifier
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java26
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java14
2 files changed, 36 insertions, 4 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java
index 1b01a5f32f..34786e39b2 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java
@@ -98,6 +98,7 @@ public static Test suite() {
suite.addTest(new JavaSearchBugs8Tests("testBug424119_002"));
suite.addTest(new JavaSearchBugs8Tests("testBug424119_003"));
suite.addTest(new JavaSearchBugs8Tests("testBug427537a"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug427677"));
return suite;
}
class TestCollector extends JavaSearchResultCollector {
@@ -1752,5 +1753,30 @@ public void testBug427537a() throws CoreException {
"src/b427537/X.java void b427537.X.main(String[]) [I] EXACT_MATCH"
);
}
+/**
+ * @bug 427677: [1.8][search] NPE in MatchLocator.reportMatching with unresolved NameQualifiedType qualifier
+ * @test test
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=427677"
+ */
+public void testBug427677() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b427677/X.java",
+ "import java.lang.annotation.*; \n" +
+ "class X implements unresolved. @Marker1 Collection<Integer> { } \n" +
+ "@Target (ElementType.TYPE_USE) \n" +
+ "@interface Marker1 {}"
+ );
+ SearchPattern pattern = SearchPattern.createPattern(
+ "Marker1",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+ new SearchEngine(this.workingCopies).search(pattern,
+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+ getJavaSearchWorkingCopiesScope(),
+ this.resultCollector,
+ null);
+ assertSearchResults("src/b427677/X.java b427677.X [Marker1] EXACT_MATCH");
+}
// Add new tests in JavaSearchBugs8Tests
} \ No newline at end of file
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 2a2c494506..66caf9d0e5 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
@@ -2325,6 +2325,8 @@ protected void reportMatching(AbstractMethodDeclaration method, TypeDeclaration
* @param otherElements TODO
*/
protected void reportMatching(Annotation[] annotations, IJavaElement enclosingElement, IJavaElement[] otherElements, Binding elementBinding, MatchingNodeSet nodeSet, boolean matchedContainer, boolean enclosesElement) throws CoreException {
+ if (annotations == null)
+ return;
for (int i=0, al=annotations.length; i<al; i++) {
Annotation annotationType = annotations[i];
IJavaElement localAnnotation = null;
@@ -2720,7 +2722,9 @@ protected void reportMatching(TypeDeclaration type, IJavaElement parent, int acc
if (superClass != null) {
reportMatchingSuper(superClass, enclosingElement, type.binding, nodeSet, matchedClassContainer);
for (int i = 0, length = superClass.annotations == null ? 0 : superClass.annotations.length; i < length; i++) {
- reportMatching(superClass.annotations[i], enclosingElement, null, type.binding, nodeSet, matchedClassContainer, enclosesElement);
+ Annotation[] annotations = superClass.annotations[i];
+ if (annotations == null) continue;
+ reportMatching(annotations, enclosingElement, null, type.binding, nodeSet, matchedClassContainer, enclosesElement);
}
}
TypeReference[] superInterfaces = type.superInterfaces;
@@ -2728,9 +2732,11 @@ protected void reportMatching(TypeDeclaration type, IJavaElement parent, int acc
for (int i = 0, l = superInterfaces.length; i < l; i++) {
reportMatchingSuper(superInterfaces[i], enclosingElement, type.binding, nodeSet, matchedClassContainer);
TypeReference typeReference = type.superInterfaces[i];
- if (typeReference != null && typeReference.annotations != null) {
- for (int j = 0, length = typeReference.annotations.length; j < length; j++) {
- reportMatching(typeReference.annotations[j], enclosingElement, null, type.binding, nodeSet, matchedClassContainer, enclosesElement);
+ Annotation[][] annotations = typeReference != null ? typeReference.annotations : null;
+ if (annotations != null) {
+ for (int j = 0, length = annotations.length; j < length; j++) {
+ if (annotations[j] == null) continue;
+ reportMatching(annotations[j], enclosingElement, null, type.binding, nodeSet, matchedClassContainer, enclosesElement);
}
}
}

Back to the top