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.

Bug 131317

Summary: NullPointerException at org.netbeans.modules.groovy.editor.AstPath.find
Product: groovy Reporter: akochnev <akochnev>
Component: EditorAssignee: schmidtm <schmidtm>
Status: RESOLVED FIXED    
Severity: blocker    
Priority: P4    
Version: 6.x   
Hardware: All   
OS: All   
URL: http://statistics.netbeans.org/exceptions/detail.do?id=41006
Issue Type: DEFECT Exception Reporter: 41006
Attachments: stacktrace

Description akochnev 2008-03-27 17:05:07 UTC
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.
Comment 1 akochnev 2008-03-27 17:05:18 UTC
Created attachment 59229 [details]
stacktrace
Comment 2 schmidtm 2008-03-31 17:47:56 UTC
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.

Comment 3 schmidtm 2008-04-03 15:57:45 UTC
Added testcase:

http://hg.netbeans.org/main/contrib/rev/d3c372f84ed9

This issue might be (somehow) related to GROOVY-1443
Comment 4 schmidtm 2008-04-11 10:16:34 UTC
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?
Comment 5 schmidtm 2008-04-14 12:46:06 UTC
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

Comment 6 schmidtm 2008-04-14 12:48:25 UTC
This is the changeset for the sanity-checks:

http://hg.netbeans.org/main/contrib/rev/abb1279adf5c
Comment 7 martin_adamek 2008-04-29 08:40:39 UTC
Ok, NPE is fixed, so I am closing this one.
Comment 8 Quality Engineering 2008-05-20 05:07:50 UTC
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