This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Build: NetBeans IDE Dev (Build 200803251204) VM: Java HotSpot(TM) Client VM, 1.6.0_02-b06, Java(TM) SE Runtime Environment, 1.6.0_02-b06 OS: Windows XP, 5.1, x86 User Comments: [1,2,3,4].each { n -> println n } Works fine. It should also be valid to specify the type of closure argument as in (and it works in a regular Groovy Console): [1,2,3,4].each { Number n -> println n.intValue() } This is the exception when I hit Ctrl-Space to get code completion to get the methods of the Number n closure parameter.
Created attachment 59229 [details] stacktrace
Here's an easy way to reproduce: 1.) create new groovy script 2.) Replace body from template with: def m() { Object t = new Object() t. } 3.) try to complete t. I took a quick look in the file to figure out what's wrong AstPath.java find(): ModuleNode moduleNode = (ModuleNode) node; PathFinderVisitor pathFinder = new PathFinderVisitor(moduleNode.getContext(), line, column); moduleNode == null which causes the NPE. Not sure whether we should guard this with an assert and fix it in the Completer ... I'll try to take a look at it this week.
Added testcase: http://hg.netbeans.org/main/contrib/rev/d3c372f84ed9 This issue might be (somehow) related to GROOVY-1443
The root cause seems to be a fuzzy error-location reported by the groovy compiler. See this posting to the groovy development list: Hi *, a) if i compile this: 1 def m() { 2 Object x = new Object() 3 x. 4 // println "Hi" 5 } i get: startup failed, C:\temp\error.groovy: 5: unexpected token: } @ line 5, colum n 1. b) if i uncomment the println statement: 1 def m() { 2 Object x = new Object() 3 x. 4 println "Hi" 5 } i get *no* error-message and the compile succeeds. Strange. I think the error itself is in line 3. We need to have precise error-locations, since we constantly modify our source-model to get a compilable piece and use it's AST. I'm facing this issue while working on the method-completion (therefore x.<HIT CTRL-SPACE>). c) This is what javac gives: 1 public class JavaError{ 2 public static void main(String[] args) { 3 } 4 5 void m() { 6 Object x = new Object(); 7 x. 8 } 9 } JavaError.java:8: <identifier> expected } ^ JavaError.java:7: not a statement x. ^ 2 errors This gives me the error location and I'm able to "sanatize" the code by removing the dot, deleting the line or the like. I've did the tests using 1.5.4. Do you consider this a Bug?
Hi, Since the sanatizer in GroovyParser.java could not "repair" this code-snippet, i don't get a AST root. Therefore i could not complete this. I've enriched the code with some sanity-checks to avoid Assertions or NPE's but could not do much more unless the Groovy-Compiler hints a line delete. This might turn into an RFE against the Groovy-Compiler, please refer to this discussion on groovy-dev: http://www.nabble.com/wrong-error-message-location-from-groovy-compiler--tt16628468.html#a16628468
This is the changeset for the sanity-checks: http://hg.netbeans.org/main/contrib/rev/abb1279adf5c
Ok, NPE is fixed, so I am closing this one.
Integrated into 'main-golden', available in NB_Trunk_Production #206 build Changeset: http://hg.netbeans.org/main/rev/03b0107e47a6 User: Matthias Schmidt <schmidtm@netbeans.org> Log: Testcase for #131317, some assertions to guard utilies