Community
Participate
Working Groups
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)
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.
Here is a patch for this. Same patch has to be applied to PublicScanner.
Created attachment 6189 [details] Apply this patch on the Scanner class.
Created attachment 6190 [details] Apply this patch on PublicScanner.
Fixed and released in HEAD. Regression test added.
Verified.