Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-880

NullPointerException at groovy.ui.GroovyMain.run(GroovyMain.java:267)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-JSR-1
    • 1.0-JSR-2
    • groovy-jdk
    • None
    • All

    Description

      //demo.groovy
      println [1,2].collect

      {it + 1}

      run this file, the output is
      Caught: groovy.lang.MissingPropertyException: No such property: println for class: demo
      java.lang.NullPointerException
      at groovy.ui.GroovyMain.run(GroovyMain.java:267)
      at groovy.ui.GroovyMain.process(GroovyMain.java:235)
      at groovy.ui.GroovyMain.main(GroovyMain.java:138)
      at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:92)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
      at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
      at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:429)
      at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

      The first message is caused by defect GROOVY-277, but the NullPointerException is caused by "element.getFileName() can return null", below is the source code.
      StackTraceElement[] stackTrace = e.getStackTrace();
      for (int i = 0; i < stackTrace.length; i++) {
      StackTraceElement element = stackTrace[i];
      if (!element.getFileName().endsWith(".java"))

      { System.err.println("\tat " + element); }

      }
      From the javadoc of StackTraceElement#getFileName()
      /**

      • Returns the name of the source file containing the execution point
      • represented by this stack trace element. Generally, this corresponds
      • to the <tt>SourceFile</tt> attribute of the relevant <tt>class</tt>
      • file (as per <i>The Java Virtual Machine Specification</i>, Section
      • 4.7.7). In some systems, the name may refer to some source code unit
      • other than a file, such as an entry in source repository.
        *
      • @return the name of the file containing the execution point
      • represented by this stack trace element, or <tt>null</tt> if
      • this information is unavailable.
        */
        , we can see, getFileName() may return null

      Attachments

        Activity

          People

            Unassigned Unassigned
            wangbin wangbin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: