Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.5.7, 1.6-beta-2
-
None
-
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.
Attachments
Issue Links
- relates to
-
GROOVY-3203 ProxyGenerator.instantiateDelegate(Map, Class) behavior should align with ConvertedMap behavior
- Closed