### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java,v retrieving revision 1.94 diff -u -r1.94 JavaSearchBugsTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 10 Nov 2006 21:40:37 -0000 1.94 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 16 Nov 2006 16:29:41 -0000 @@ -159,6 +159,7 @@ addLibraryEntry(JAVA_PROJECT, "/JavaSearchBugs/lib/b95152.jar", false); addLibraryEntry(JAVA_PROJECT, "/JavaSearchBugs/lib/b123679.jar", false); addLibraryEntry(JAVA_PROJECT, "/JavaSearchBugs/lib/b140156.jar", false); + addLibraryEntry(JAVA_PROJECT, "/JavaSearchBugs/lib/b164791.jar", false); } public void tearDownSuite() throws Exception { deleteProject("JavaSearchBugs"); @@ -7697,4 +7739,27 @@ "src/A.java int A.x(int) [param] EXACT_MATCH" ); } + +/** + * @bug 164791: [search] Type reference reports anonymous type in invalid class file + * @test Ensure that match on anonymous type in local type is well reported + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=164791" + */ +public void testBug164791() throws CoreException { + IType type = getClassFile("JavaSearchBugs", "lib/b164791.jar", "pack", "ELPM.class").getType(); + JavaSearchResultCollector collector = new JavaSearchResultCollector() { + public void acceptSearchMatch(SearchMatch searchMatch) throws CoreException { + super.acceptSearchMatch(searchMatch); + IJavaElement element = (IJavaElement) searchMatch.getElement(); + assertTrue("Search match element "+element.getElementName()+" should exist!!!", element.exists()); + } + }; + collector.showAccuracy = true; + search(type, REFERENCES, getJavaSearchScopeBugs(), collector); + assertSearchResults( + "lib/b164791.jar test. EXACT_MATCH\n" + + "lib/b164791.jar test. EXACT_MATCH", + collector + ); +} } \ No newline at end of file #P org.eclipse.jdt.core Index: search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java,v retrieving revision 1.283 diff -u -r1.283 MatchLocator.java --- search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 6 Nov 2006 14:28:55 -0000 1.283 +++ search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 16 Nov 2006 16:29:46 -0000 @@ -708,11 +708,14 @@ return ((CompilationUnit) openable).getType(simpleTypeName); IType binaryType = ((ClassFile) openable).getType(); - if (simpleTypeName.equals(binaryType.getTypeQualifiedName())) + String binaryTypeQualifiedName = binaryType.getTypeQualifiedName(); + if (simpleTypeName.equals(binaryTypeQualifiedName)) return binaryType; // answer only top-level types, sometimes the classFile is for a member/local type try { - IClassFile classFile = binaryType.getPackageFragment().getClassFile(simpleTypeName + SuffixConstants.SUFFIX_STRING_class); + // type name may be null for anonymous (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=164791) + String classFileName = simpleTypeName.length() == 0 ? binaryTypeQualifiedName : simpleTypeName; + IClassFile classFile = binaryType.getPackageFragment().getClassFile(classFileName + SuffixConstants.SUFFIX_STRING_class); return classFile.getType(); } catch (JavaModelException e) { // ignore as implementation of getType() cannot throw this exception @@ -1621,7 +1624,9 @@ try { JavaElement javaElement = (JavaElement)match.getElement(); System.out.println("\tJava element: "+ javaElement.toStringWithAncestors()); //$NON-NLS-1$ - if (!javaElement.exists()) System.out.println("\t\tWARNING: this element does NOT exist!"); //$NON-NLS-1$ + if (!javaElement.exists()) { + System.out.println("\t\tWARNING: this element does NOT exist!"); //$NON-NLS-1$ + } } catch (Exception e) { // it's just for debug purposes... ignore all exceptions in this area }