Bug 78581 - [search] NPE while searching
Summary: [search] NPE while searching
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M4   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-14 09:55 EST by Nico Seessle CLA
Modified: 2004-12-14 11:51 EST (History)
0 users

See Also:


Attachments
zipped Projects used to reproduce the problem (691.99 KB, application/octet-stream)
2004-11-20 15:49 EST, Nico Seessle CLA
no flags Details
zipped Projects used to reproduce the problem (932.23 KB, application/zip)
2004-11-20 16:19 EST, Nico Seessle CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nico Seessle CLA 2004-11-14 09:55:19 EST
Eclipse 3.1M3 and 200411101000 (didn't happen in 3.1M2)

I'm getting a NPE while search for all references to a method (String
de.hmorga.util.Format#format(long d, String format)) (see below).

directoryCache == null, and qualifiedPackageName= "org/apache/xalan/res".

When searching for other methods in the same class (for example String
de.hmorga.util.Format#format(double d, String format), or String
de.hmorga.util.Format#format(Number n, String format)) this does not happen.

Adding "if (directoryCache == null) return null;" to the top of String[]
org.eclipse.jdt.internal.core.search.matching.ClasspathSourceDirectory#directoryList(String
qualifiedPackageName) "fixes" this problem for me. (I get the same number of
matches as I get with 3.1M2)

java.lang.NullPointerException
	at
org.eclipse.jdt.internal.core.search.matching.ClasspathSourceDirectory.directoryList(ClasspathSourceDirectory.java:53)
	at
org.eclipse.jdt.internal.core.search.matching.ClasspathSourceDirectory.doesFileExist(ClasspathSourceDirectory.java:82)
	at
org.eclipse.jdt.internal.core.search.matching.ClasspathSourceDirectory.findClass(ClasspathSourceDirectory.java:103)
	at
org.eclipse.jdt.internal.core.search.matching.JavaSearchNameEnvironment.findClass(JavaSearchNameEnvironment.java:138)
	at
org.eclipse.jdt.internal.core.search.matching.JavaSearchNameEnvironment.findType(JavaSearchNameEnvironment.java:169)
	at
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:116)
	at
org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:169)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getTypeOrPackage(Scope.java:2246)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getType(Scope.java:2017)
	at
org.eclipse.jdt.internal.core.search.matching.MethodPattern.getMethodBinding(MethodPattern.java:131)
	at
org.eclipse.jdt.internal.core.search.matching.MethodLocator.matchMethod(MethodLocator.java:141)
	at
org.eclipse.jdt.internal.core.search.matching.MethodLocator.resolveLevel(MethodLocator.java:237)
	at
org.eclipse.jdt.internal.core.search.matching.ClassFileMatchLocator.locateMatches(ClassFileMatchLocator.java:72)
	at
org.eclipse.jdt.internal.core.search.matching.MatchLocator.process(MatchLocator.java:1174)
	at
org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:775)
	at
org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:814)
	at
org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:915)
	at
org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:94)
	at
org.eclipse.jdt.internal.core.search.SearchBasicEngine.findMatches(SearchBasicEngine.java:196)
	at
org.eclipse.jdt.internal.core.search.SearchBasicEngine.search(SearchBasicEngine.java:382)
	at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:512)
	at org.eclipse.jdt.internal.ui.search.JavaSearchQuery.run(JavaSearchQuery.java:125)
	at
org.eclipse.search2.internal.ui.InternalSearchUI$InternalSearchJob.run(InternalSearchUI.java:85)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:66)
Comment 1 Frederic Fusier CLA 2004-11-19 04:04:32 EST
Theoretically directoryList should NOT be null...
It is initialized at the beginning of the search while computing classpath
entries and reset at the end of the search to release memory...

It would be really helpful if you can find a small test case which can help me
to reproduce the problem and see where I miss to set this variable. The best
thing would be to put your class de.hmorga.util.Format in a new workspace, fix
all compilation errors by reducing the code at the maximum but always getting
the NPE while searching.

Of course, if you cannot find an example to reproduce it easily, I'll apply the
solution to verify that this variable is not null but it would be only fix the
consequence not the cause of the problem...
Thx
Comment 2 Nico Seessle CLA 2004-11-20 15:48:50 EST
Wow, that was hard to reproduce. The smallest test-case which I could produce
still weights in with ~700kB (hope that's not a big problem).

I think any other jar file than ant.jar would work to reproduce the bug, unless
it contains a method with the same signature that you are searching for - but
this is just a rough guess, and I was too lazy (already spent several hours to
bring it down to ~700kB) to produce a smaller example.

- Create a new Workspace-Directory (outside Eclipse)
- Extract the attached ZIP into this directory
- launch Eclipse 3.1M3 and specify the directory as the workspace
- create two java projects (reusing the extracted zip), in the order "p3", "p2"
- fix the classpath for "P2" (the "ant.jar" is contained in the project "P2",
but MUST be added thru "add external jar" to reproduce the problem)
- open the class "Format" in "P3" and do a "search, references, workspace" for
"format(long d, String format)"
=> WORKS OK, this is as expected!
- go to preferences, java, installed jres; add a new "JRE" (but use a JDK!) and
specifiy this as the default (jdk 1.4.2_05 and 1.5.0 worked for me for the next
steps to reproduce the problem); set the JDK as the default
- doing ths search again now causes the stack-trace mentioned in the bud report.
Comment 3 Nico Seessle CLA 2004-11-20 15:49:59 EST
Created attachment 16031 [details]
zipped Projects used to reproduce the problem
Comment 4 Nico Seessle CLA 2004-11-20 16:17:47 EST
Ah, crap...

Note to self: don't try to reduce things more than needed.

Will add a new attachment, as the current one seems to work only once (when
restarting eclipse everything seems to work well). The new examples survived
three restarts (and probably will survive more) and should make debugging easier.

- Now there are three projects
- the jar files (for P2) are in the sub-directory "xxx", which is NOT a eclipse
project

Additional note: 
- removing the source-attachment from the jdk-rt.jar removed the problem
- adding a source-attachment to the jre-rt.jar also causes the problem
Comment 5 Nico Seessle CLA 2004-11-20 16:19:24 EST
Created attachment 16032 [details]
zipped Projects used to reproduce the problem
Comment 6 Frederic Fusier CLA 2004-11-21 07:53:56 EST
I'm able to get the exception now...
Thanks for these detailed instructions and test case.
Comment 7 Frederic Fusier CLA 2004-11-21 08:24:54 EST
Here's the minimal test case to reproduce:
Project P2:
.classpath:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" path=""/>
	<classpathentry kind="src" path="/P3"/>
	<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/1.4.2"/>
	<classpathentry kind="lib"
path="D:/e/v31/eclipse/plugins/org.apache.ant_1.6.2/lib/ant.jar"/>
	<classpathentry kind="output" path=""/>
</classpath>

Project P3:
.classpath:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" path=""/>
	<classpathentry sourcepath="JRE_SRC" kind="var" path="JRE_LIB"/>
	<classpathentry kind="output" path=""/>
</classpath>
Format.java:
public class Format {
    public static String format(double d, String format) {
        return "";
    }

    public static String format(long d, String format) {
        return "";
    }

}

Workspace default JRE: 1.5.0

Search for reference in workspace to method format(long,String) from Outline
view and then you'll get Java Search error dialog:
An internal error occured during: "Java Search"
Comment 8 Frederic Fusier CLA 2004-11-21 11:26:17 EST
Fixed.

The NPE does no longer happen now.

[jdt-core-internal]
Change done in MatchLocator#initialize(IJavaProject,int).
JavaSearchNameEnvironment was always cleaned-up although it is reused when
there's only oe possible match.
No test case added as it was too complex to reproduce using JUnit tests.
Run scenario described in comment 7 to verify that it's fixed.
Comment 9 Olivier Thomann CLA 2004-12-14 11:51:13 EST
Verified in 200412140800