You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/03/17 21:22:00 UTC

[jira] [Commented] (GROOVY-9523) MissingMethodException when referencing a private enum method

    [ https://issues.apache.org/jira/browse/GROOVY-9523?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17303734#comment-17303734 ] 

Eric Milles commented on GROOVY-9523:
-------------------------------------

See also GROOVY-8905 and GROOVY-9987

The enum constant body is an anonymous inner class.  It tries to access a private method of the outer class.  There may be missing bridging in this case.  {{@CompileStatic}} is the usual workaround; I am looking at 9524 to fix the stack issue.

> MissingMethodException when referencing a private enum method
> -------------------------------------------------------------
>
>                 Key: GROOVY-9523
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9523
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.5.11
>            Reporter: Mauro Molinari
>            Priority: Major
>
> Consider this Groovy class:
>  
> {code:groovy}
> package test64
> import groovy.transform.CompileDynamic
> import groovy.transform.CompileStatic
> @CompileStatic
> class Test64 {
> 	@CompileDynamic
> 	static enum ShippingAddressSynchType {
> 		ACCOUNTING {
> 			@Override
> 			void synch(Test64 customer) {
> 				truncate('foo', 2)
> 			}
> 		};
> 		void synch(Test64 customer) { }
> 		private String truncate(String input, int maxLength) {
> 			if(!input)
> 				return input
> 			if(input.length() > maxLength)
> 				input = input[0..maxLength - 1]
> 			return input
> 		}
> 	}
> }
> {code}
> and a Java class to run it:
> {code:java}
> package test64;
> import test64.Test64.ShippingAddressSynchType;
> public class Test64Main {
> 	public static void main(String[] args) {
> 		Test64 t = new Test64();
> 		ShippingAddressSynchType.ACCOUNTING.synch(t);
> 	}
> }
> {code}
> If you run this code, you'll get:
> {noformat}
> Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: test64.Test64$ShippingAddressSynchType$1.truncate() is applicable for argument types: (String, Integer) values: [foo, 2]
>         at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:70)
>         at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:83)
>         at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
>         at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:156)
>         at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:176)
>         at test64.Test64$ShippingAddressSynchType$1.synch(Test64.groovy:14)
>         at test64.Test64Main.main(Test64Main.java:9)
> {noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)