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/07 01:36:00 UTC

[jira] [Resolved] (GROOVY-9966) Build Error: StringIndexOutOfBoundsException when the stars align...

     [ https://issues.apache.org/jira/browse/GROOVY-9966?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles resolved GROOVY-9966.
---------------------------------
    Fix Version/s: 4.0.0-alpha-3
       Resolution: Fixed

> Build Error: StringIndexOutOfBoundsException when the stars align...
> --------------------------------------------------------------------
>
>                 Key: GROOVY-9966
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9966
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 3.0.7
>         Environment: Windows 10
> jdk-11.0.10.9-hotspot
> IntelliJ 2020.3.2
>            Reporter: mgroovy
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-alpha-3
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> *Problem*
>  Trying to build the sample test code below throws:
> {code:java}
> Groovyc: While compiling [tests of GroovySimple]: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
> 	at java.base/java.lang.String.substring(String.java:1841)
> 	at org.apache.groovy.util.BeanUtils.capitalize(BeanUtils.java:54)
> 	at org.codehaus.groovy.control.StaticImportVisitor.getAccessorName(StaticImportVisitor.java:519)
> 	at org.codehaus.groovy.control.StaticImportVisitor.findStaticPropertyAccessor(StaticImportVisitor.java:528)
> 	at org.codehaus.groovy.control.StaticImportVisitor.findStaticPropertyAccessorGivenArgs(StaticImportVisitor.java:524)
> 	at org.codehaus.groovy.control.StaticImportVisitor.findStaticMethodImportFromModule(StaticImportVisitor.java:505)
> 	at org.codehaus.groovy.control.StaticImportVisitor.transformPropertyExpression(StaticImportVisitor.java:384)
> 	at org.codehaus.groovy.control.StaticImportVisitor.transform(StaticImportVisitor.java:130)
> 	at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitExpressionStatement(ClassCodeExpressionTransformer.java:108)
> 	at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:40)
> 	at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:86)
> 	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:164)
> 	at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)
> 	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:138)
> 	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:111)
> 	at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitConstructorOrMethod(ClassCodeExpressionTransformer.java:66)
> 	at org.codehaus.groovy.control.StaticImportVisitor.visitConstructorOrMethod(StaticImportVisitor.java:108)
> 	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:106)
> 	at org.codehaus.groovy.ast.ClassNode.visitMethods(ClassNode.java:1099)
> 	at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1092)
> 	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:52)
> 	at org.codehaus.groovy.control.CompilationUnit.lambda$addPhaseOperations$3(CompilationUnit.java:209)
> 	at org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:942)
> 	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:671)
> 	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:635)
> 	at org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:48)
> 	at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner.runGroovyc(DependentGroovycRunner.java:118)
> 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> 	at org.jetbrains.groovy.compiler.rt.GroovycRunner.intMain2(GroovycRunner.java:81)
> 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
> 	at org.jetbrains.jps.incremental.groovy.InProcessGroovyc.runGroovycInThisProcess(InProcessGroovyc.java:167)
> 	at org.jetbrains.jps.incremental.groovy.InProcessGroovyc.lambda$runGroovyc$0(InProcessGroovyc.java:77)
> 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
> 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
> 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
> 	at java.base/java.lang.Thread.run(Thread.java:834)
> {code}
> It seems to be the result of the following three things coming together in the code:
>  # any static star-import (also unused)
>  # dynamically accessing the result of any method...
>  # ...which is passed a GString literal with an embedded variable at its end
> *Expected*
>  Code should compile.
> *Sample Code*
> {code:java}
> import org.junit.Ignore
> import org.junit.Test
> import static java.util.Arrays.* // any static star-import
> class Groovy3Bugs_2021_03_04 {
> 	@Test
> 	@Ignore
> 	void 'Groovy 3-0-7 StringIndexOutOfBoundsException build error'() {
> 		//final someVarThatComesLastInGstring = 'any text'
> 		final someVarThatComesLastInGstring = 123.456 // Type of var irrelevant
> 		someMethod("$someVarThatComesLastInGstring").whatever // Groovy 3.0.7: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
> 	}
> 	Object someMethod(def x) { x }
> }
> {code}



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