IDEA X with Groovy/Maven support

I am having an issue running a Groovy test case based on an error compiling my Groovy class.
This works in the maven project underneath, but not in IDEA

Groovy Class:

package com.baselogic.chapter05.groovy

import org.apache.commons.lang.StringEscapeUtils

class StringUtilities {

    public static String blankIfNull(String s) {
        return (s == null) ? "" : s;
    }

    public static String valueIfBlank(String target, String value) {
        return (blankIfNull(target) == "") ? value : target
    }

    public static String nullIfBlank(String value) {
        return valueIfBlank(value, null);
    }

    public static boolean toBoolean(String value) {
        return ("True".equalsIgnoreCase(value) || "T".equalsIgnoreCase(value)
            || "Yes".equalsIgnoreCase(value) || "Y".equalsIgnoreCase(value))
    }

    public static String toYesNo(boolean value) {
        return (value? 'Yes': 'No')
    }

    public static String htmlEncode(String s) {
        return StringEscapeUtils.escapeHtml(s)
    }

    /**
     * Map map = javax.servlet.ServletRequest.getParameterMap()
     * String s = getRequestQueryString(map)
     *
     * or
     * String s = getRequestQueryString(javax.servlet.ServletRequest.getParameterMap())
     */
    public static String getRequestQueryString(Map<String, String> parameters) {
        StringBuilder sb = new StringBuilder();
        parameters.each() {key, value -> sb.append("${key}=${value}&") };
        return sb.toString()
    }

    public static String returnValidAlphaNumericCharacters(String s) {
        return s.replaceAll(/([^0-9A-Za-z]+)/, '')
    }
    public static String returnValidDigitCharacters(String s) {
        return s.replaceAll(/([^0-9]+)/, '')
    }
}


Error:

BUG! exception in phase 'semantic analysis' in source unit 'C:\usr\SYNCH\PACKT\3166\Chapters_Code\ch05\src\main\groovy\com\baselogic\chapter05\groovy\StringUtilities.groovy' String index out of range: -1
    at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:865)
    at org.codehaus.groovy.control.CompilationUnit.semanticAnalysis(CompilationUnit.java:613)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:453)
    at org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:43)
    at org.jetbrains.groovy.compiler.rt.GroovycRunner.main(GroovycRunner.java:128)
    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:613)
    at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:75)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.AbstractStringBuilder.deleteCharAt(AbstractStringBuilder.java:762)
    at java.lang.StringBuffer.deleteCharAt(StringBuffer.java:378)
    at groovy.lang.GroovyClassLoader.getClassPath(GroovyClassLoader.java:343)
    at groovy.lang.GroovyClassLoader.getSourceFile(GroovyClassLoader.java:643)
    at groovy.lang.GroovyClassLoader.access$200(GroovyClassLoader.java:83)
    at groovy.lang.GroovyClassLoader$1$1.run(GroovyClassLoader.java:98)
    at java.security.AccessController.doPrivileged(Native Method)
    at groovy.lang.GroovyClassLoader$1.loadGroovySource(GroovyClassLoader.java:93)
    at org.codehaus.groovy.control.ResolveVisitor.resolveToScript(ResolveVisitor.java:299)
    at org.codehaus.groovy.control.ResolveVisitor.resolve(ResolveVisitor.java:228)
    at org.codehaus.groovy.control.ResolveVisitor.resolveFromModule(ResolveVisitor.java:435)
    at org.codehaus.groovy.control.ResolveVisitor.resolve(ResolveVisitor.java:228)
    at org.codehaus.groovy.control.ResolveVisitor.resolve(ResolveVisitor.java:206)
    at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:196)
    at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:201)
    at org.codehaus.groovy.control.ResolveVisitor.visitMethod(ResolveVisitor.java:161)
    at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:832)
    at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:706)
    at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:123)
    at org.codehaus.groovy.control.CompilationUnit$5.call(CompilationUnit.java:572)
    at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:861)
    ... 9 more


I attached the project zip.



Attachment(s):
ch05.zip
2 comments
Comment actions Permalink

I updated to the EAP ideaIU-106.273 but I get the same error.
WHen I run mvn clean package the tests run fine though.

0
Comment actions Permalink

I just upgraded and the issue does not occur anymore.

0

Please sign in to leave a comment.