Bug 5955 - NPE in LookupEnvironment
Summary: NPE in LookupEnvironment
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P1 normal (vote)
Target Milestone: 2.0 M1   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 5612
  Show dependency tree
 
Reported: 2001-11-15 10:37 EST by Darin Wright CLA
Modified: 2002-01-11 09:22 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Wright CLA 2001-11-15 10:37:42 EST
Using 20011114, when I try any evaluation in the debugger, I get the following 
NPE:

java.lang.NullPointerException
	at 
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createPackage
(LookupEnvironment.java:320)
	at 
org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.buildTypeBindings
(CompilationUnitScope.java:90)
	at 
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.buildTypeBindings
(LookupEnvironment.java:110)
	at org.eclipse.jdt.internal.compiler.Compiler.beginToCompile
(Compiler.java:224)
	at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:247)
	at org.eclipse.jdt.internal.eval.Evaluator.getClasses
(Evaluator.java:113)
	at org.eclipse.jdt.internal.eval.EvaluationContext.evaluateVariables
(EvaluationContext.java:308)
	at org.eclipse.jdt.internal.eval.EvaluationContext.evaluate
(EvaluationContext.java:191)
	at 
org.eclipse.jdt.internal.core.eval.EvaluationContextWrapper.evaluateCodeSnippet
(EvaluationContextWrapper.java:158)
	at org.eclipse.jdt.internal.debug.eval.LocalEvaluationEngine$2.run
(LocalEvaluationEngine.java:456)
	at java.lang.Thread.run(Thread.java:498)
Comment 1 Philipe Mulet CLA 2001-11-15 16:29:40 EST
This indicates the name environment which got passed to the 
IEvaluationContext.evaluate(...) call was null.

This reveals that the project has no built state (#getLastBuiltState), which is 
probably true if using the new builder.

So turn off the new builder, and we will had support for it soon.
Comment 2 Kent Johnson CLA 2001-11-16 10:06:39 EST
The evaluation context should create its own name environment using something 
like the code below... it does not need to know a new build state since there 
is nothing in the state that it needs. It does not want to see source files so 
create binary classpath directories for every project. This code comes from 
JavaBuilder.initializeBuilder(), if it would be better in NameEnvironment then 
we can move it.

workspaceRoot = currentProject.getWorkspace().getRoot();
outputFolder = (IContainer) workspaceRoot.findMember
(javaProject.getOutputLocation());
if (outputFolder == null) {
	outputFolder = workspaceRoot.getFolder(javaProject.getOutputLocation());
	createFolder(outputFolder);
}

IClasspathEntry[] entries = ((JavaProject) javaProject).getExpandedClasspath
(true);
int cpCount = 0;
int max = entries.length;
this.classpath = new ClasspathLocation[max];

nextEntry : for (int i = 0; i < max; i++) {
	IClasspathEntry entry = entries[i];
	Object target = JavaModel.getTarget(workspaceRoot, entry.getPath(), 
true);
	if (target == null) continue nextEntry;

	if (target instanceof IResource) {
		IResource resource = (IResource) target;
		switch(entry.getEntryKind()) {
			case IClasspathEntry.CPE_SOURCE :
				if (!(resource instanceof IContainer)) continue 
nextEntry;
				classpath[cpCount++] = 
ClasspathLocation.forRequiredProject(outputFolder.getLocation().toString());
				continue nextEntry;

			case IClasspathEntry.CPE_PROJECT :
				if (!(resource instanceof IProject)) continue 
nextEntry;
				IProject prereqProject = (IProject) resource;
				IPath outputLocation = getJavaProject
(prereqProject).getOutputLocation();
				IResource prereqOutputFolder;
				if (prereqProject.getFullPath().equals
(outputLocation)) {
					prereqOutputFolder = prereqProject;
				} else {
					prereqOutputFolder = 
workspaceRoot.findMember(outputLocation);
					if (prereqOutputFolder == null || !
prereqOutputFolder.exists() || !(prereqOutputFolder instanceof IFolder))
						continue nextEntry;
				}
				classpath[cpCount++] = 
ClasspathLocation.forRequiredProject(prereqOutputFolder.getLocation().toString
());
				continue nextEntry;

			case IClasspathEntry.CPE_LIBRARY :
				if (resource instanceof IFile) {
					String extension = entry.getPath
().getFileExtension();
					if (!(JAR_EXTENSION.equalsIgnoreCase
(extension) || ZIP_EXTENSION.equalsIgnoreCase(extension)))
						continue nextEntry;
				} else if (!(resource instanceof IFolder)) {
					continue nextEntry;
				}
				classpath[cpCount++] = 
ClasspathLocation.forLibrary(resource.getLocation().toString());
				continue nextEntry;
		}
	} else if (target instanceof File) {
		String extension = entry.getPath().getFileExtension();
		if (!(JAR_EXTENSION.equalsIgnoreCase(extension) || 
ZIP_EXTENSION.equalsIgnoreCase(extension)))
			continue nextEntry;
		classpath[cpCount++] = ClasspathLocation.forLibrary
(entry.getPath().toString());
	}
}
if (cpCount < max)
	System.arraycopy(classpath, 0, (classpath = new ClasspathLocation
[cpCount]), 0, cpCount);
Comment 3 Philipe Mulet CLA 2001-11-19 10:42:59 EST
Fixed as indicated above.