Bug 43485 - NPE in SearchEngine
Summary: NPE in SearchEngine
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-09-23 06:25 EDT by Martin Aeschlimann CLA
Modified: 2003-10-08 10:30 EDT (History)
0 users

See Also:


Attachments
Apply this patch on the Scanner class. (1.09 KB, patch)
2003-09-23 08:14 EDT, Olivier Thomann CLA
no flags Details | Diff
Apply this patch on PublicScanner. (1.20 KB, patch)
2003-09-23 08:15 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2003-09-23 06:25:01 EDT
smoke for 20030923 (jdt.core preview 20030922)

1. In the following code select getName and do a search for declarations.
 --> NPE

public class A {
	public String getName() {
		Runnable run= new Runnable() {
			public void run() {
				// TODO Auto-generated method stub
	                }
		};
		return "xx";
	}
}

Caused by: java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.parser.Scanner.setSource(Scanner.java:3017)
	at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:5934)
	at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:5916)
	at org.eclipse.jdt.internal.compiler.parser.Parser.dietParse(Parser.java:4663)
	at
org.eclipse.jdt.internal.core.search.matching.MatchLocator.buildBindings(MatchLocator.java:289)
	at
org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:582)
	at
org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:641)
	at
org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:750)
	at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:515)
	at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:442)
	at
org.eclipse.jdt.internal.ui.search.JavaSearchOperation.execute(JavaSearchOperation.java:90)
	at
org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:71)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1586)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1603)
	at
org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:85)
	at
org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:101)
Comment 1 Olivier Thomann CLA 2003-09-23 08:08:49 EDT
The fix is easy.
public final void setSource(char[] source){
	//the source-buffer is set to sourceString

	if (source == null) {
		this.source = CharOperation.NO_CHAR;
	} else {
		this.source = source;
	}
	startPosition = -1;
	eofPosition = source.length;
	initialPosition = currentPosition = 0;
	containsAssertKeyword = false;
	withoutUnicodeBuffer = new char[this.source.length];
}

source.length; should be replaced with this.source.length;
this.source cannot be null, but source can be null. We might want to rename the
parameter to prevent any other confusion.
Comment 2 Olivier Thomann CLA 2003-09-23 08:13:52 EDT
Here is a patch for this. Same patch has to be applied to PublicScanner.
Comment 3 Olivier Thomann CLA 2003-09-23 08:14:18 EDT
Created attachment 6189 [details]
Apply this patch on the Scanner class.
Comment 4 Olivier Thomann CLA 2003-09-23 08:15:43 EDT
Created attachment 6190 [details]
Apply this patch on PublicScanner.
Comment 5 Olivier Thomann CLA 2003-09-23 11:03:24 EDT
Fixed and released in HEAD.
Regression test added.
Comment 6 David Audel CLA 2003-10-08 10:30:00 EDT
Verified.