Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.8.2, 2.4.0-rc-1
-
None
Description
The original thread: http://groovy.329449.n5.nabble.com/Currying-an-instance-method-exception-with-modifier-private-td4849071.html
The following code explains the issue:
class Base { private __value(arg) { println "$arg" } // <<< here def value = this.&__value.curry('value') def extend() { def tmp = this.&__value.curry('extend') tmp() } } class Sub extends Base { def test() { value() extend() } } new Sub().test()
Exception thrown
Sep 28, 2011 6:41:42 PM org.codehaus.groovy.runtime.StackTraceUtils sanitize WARNING: Sanitizing stacktrace: java.lang.IllegalArgumentException: Can't curry 1 arguments for a closure with 0 parameters. at org.codehaus.groovy.runtime.CurriedClosure.<init>(CurriedClosure.java:72) at org.codehaus.groovy.runtime.CurriedClosure.<init>(CurriedClosure.java:86) at groovy.lang.Closure.curry(Closure.java:527) 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:597) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:226) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:64) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at Base.<init>(ConsoleScript7:4) at Sub.<init>(ConsoleScript7) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77) at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:54) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:186) at ConsoleScript7.run(ConsoleScript7:19) at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:266) at groovy.lang.GroovyShell.run(GroovyShell.java:517) at groovy.lang.GroovyShell.run(GroovyShell.java:172) at groovy.lang.GroovyShell$run.call(Unknown Source) at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy:924) 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:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:883) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141) at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy) 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:597) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:883) at groovy.lang.Closure.call(Closure.java:410) at groovy.lang.Closure.call(Closure.java:404) at groovy.lang.Closure.run(Closure.java:488) at java.lang.Thread.run(Thread.java:662) java.lang.IllegalArgumentException: Can't curry 1 arguments for a closure with 0 parameters. at Base.<init>(ConsoleScript7:4) at Sub.<init>(ConsoleScript7) at ConsoleScript7.run(ConsoleScript7:19)
The only change it needs is to change the private to def / protected in the line marked with '// <<<'.
Similar Java code behaves correctly:
class Base { private int get() { return 17; } int a = this.get(); // <<< here public void test() { System.out.println(a); } } public class Sub extends Base { public static void main(String[] args) { new Sub().test(); } }
When Sub is instantiated, the call to the private get() is done in the superclass, who can access it.
Attachments
Issue Links
- is related to
-
GROOVY-2433 Closure in base class unable to call private methods when invoked from derived class
- Closed
- relates to
-
GROOVY-10568 MissingMethodException using method-pointer operator in superclass
- Closed
-
GROOVY-11128 implicit-this access within closure to private members in declaring class when invoked from derived class
- Closed