Groovy
  1. Groovy
  2. GROOVY-3200

Map coercion should not throw an NPE for non implemented methods from the map

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.5.7, 1.6-beta-2
    • Fix Version/s: 1.6-rc-1, 1.5.8, 1.7-beta-1
    • Component/s: None
    • Labels:
      None

      Description

      Let's consider the following example:

      interface Foo {
         def methodOne()
         def methodTwo()
      }
      
      def f = [methodOne: {-> "ONE" }] as Foo
      
      assert f.methodOne() == "ONE"
      
      // f.methodTwo()
      

      We've not provided an implementation for methodTwo(), and if we call that method, it throws a NullPointerException, leaking an implementation detail.

      As per the discussion on the mailing-list (http://www.nabble.com/Map-coercion-throwing-NPE--td20974198.html), the best thing is to indeed throw an exception, rather than returning a default value, but NPE is not the most appropriate exception to throw. It'd be best to throw an UnsupportedOperationException, like this is sometimes the case in some APIs like JDBC, AWT, JMS and others when the implementation of an API is not 100% complete when the provider doesn't support all the features possible.

        Issue Links

          Activity

          Guillaume Delcroix created issue -
          Guillaume Delcroix made changes -
          Field Original Value New Value
          Affects Version/s 1.5.7 [ 14242 ]
          Affects Version/s 1.6-beta-2 [ 14261 ]
          Fix Version/s 1.5.8 [ 14630 ]
          Fix Version/s 1.6-rc-1 [ 14009 ]
          Fix Version/s 1.7-beta-1 [ 14014 ]
          Priority Major [ 3 ] Minor [ 4 ]
          Jeff Brown made changes -
          Assignee Jeff Brown [ brownj ]
          Jeff Brown made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Hide
          Jeff Brown added a comment -

          The change to throw UnsupportedOperationException instead of NullPointerException has been committed to all 3 branches (1.5, 1.6 and 1.7)

          Show
          Jeff Brown added a comment - The change to throw UnsupportedOperationException instead of NullPointerException has been committed to all 3 branches (1.5, 1.6 and 1.7)
          Jeff Brown made changes -
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Closed [ 6 ]
          Hide
          Paul King added a comment -

          We should make:

          ProxyGenerator.instantiateDelegateFromInterface(Map, Class)
          

          follow the same behavior.

          Show
          Paul King added a comment - We should make: ProxyGenerator.instantiateDelegateFromInterface(Map, Class ) follow the same behavior.
          Paul King made changes -
          Link This issue relates to GROOVY-3203 [ GROOVY-3203 ]
          Mark Thomas made changes -
          Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
          Mark Thomas made changes -
          Workflow jira [ 12732201 ] Default workflow, editable Closed status [ 12744027 ]
          Mark Thomas made changes -
          Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
          Mark Thomas made changes -
          Workflow jira [ 12970072 ] Default workflow, editable Closed status [ 12977855 ]
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open In Progress In Progress
          45m 45s 1 Jeff Brown 13/Dec/08 16:19
          In Progress In Progress Closed Closed
          1d 46m 1 Jeff Brown 14/Dec/08 17:06

            People

            • Assignee:
              Jeff Brown
              Reporter:
              Guillaume Delcroix
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development