2

I'm new to Groovy, so it's likely I am doing something wrong. I had written a configuration to be taken in by ConfigSlurper. But something goes wrong when I actually try to parse it. My code is as follows:

class CharacterMap {
    public static final String CHARACTER_CONFIGURATION = 'location'
    static Map<String,String> characterMap = null
    public static String ASCIIize(String input)
    {
        if (!characterMap)
        {
            def property = System.getProperty( CHARACTER_CONFIGURATION )
            ConfigObject config = null
            if( property ) {
                ConfigSlurper cs = new ConfigSlurper()
                File file = new File( property )
                URL location = file.toURL()
                config = cs.parse(location)
            }
            if (config)
            {
                characterMap = config.characters
            }
            else
            {
                getAnonymousLogger().logp WARNING, getClass().name, 'constructor',
                        "Server configuration groovy file not configured with system property ${CHARACTER_CONFIGURATION}"
                return input
            }
        }
        for (String key: characterMap.keySet())
        {
            if (input.contains(key))
            {
                input = input.replace(key, characterMap.get(key))
            }
        }
        return input
    }

    public static void main(String[] args)
    {
        print ASCIIize(args[0])
    }
}

When it gets to calling the parse method it complains Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: groovy.util.ConfigSlurper.parse() is applicable for argument types: (CharacterMap, java.net.URL) As you can see, I am only passing in one argument, which was declared to be a URL. Since all the methods of the class are static and no constructor is referenced anywhere, it's kind of bizarre that an instance is being created at all, and more bizarre still that it's being passed into the parse method. I've read other people on Stack Overflow getting MissingMethodException (though usually related to closures rather than superfluous arguments), and it being blamed on Eclipse. I am running this in IntelliJ rather than Eclipse.

EDIT: In response to the comment below the groovy version is 1.8.6. Here is the stack-trace:

Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: groovy.util.ConfigSlurper.parse() is applicable for argument types: (CharacterMap, java.net.URL) values: [CharacterMap@34374a16, file:/C:/Program Files (x86)/JetBrains/IntelliJ IDEA Community Edition 11.1.2/UCP/config/CharacterMap.groovy]

Possible solutions: parse(java.net.URL), parse(groovy.lang.Script, java.net.URL), parse(groovy.lang.Script), parse(java.lang.Class), parse(java.lang.String), parse(java.util.Properties)

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:78) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:145) at groovy.util.ConfigSlurper.parse(ConfigSlurper.groovy:148) at groovy.util.ConfigSlurper$parse.call(Unknown Source) 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 ucp.cms.search.CharacterMap.ASCIIize(CharacterMap.groovy:26) at ucp.cms.search.CharacterMap.main(CharacterMap.groovy:51) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Process finished with exit code 1

WindowsWeenie
  • 389
  • 1
  • 5
  • 11

0 Answers0