grails-core icon indicating copy to clipboard operation
grails-core copied to clipboard

@GrailsCompileStatic(TypeCheckingMode.SKIP) is generating an Index 0 out of bounds for length 0 error

Open pangeaos opened this issue 2 years ago • 10 comments

Expected Behavior

My application was using Grails 5.1.2 and I decided to update to Grails 5.1.4 today. The project is getting some errors related to @GrailsCompileStatic(TypeCheckingMode.SKIP). On the previous version (5.1.2) was working as expected. I use this annotation on Controllers, Services and Domains.

this is the error Index 0 out of bounds for length 0

Any idea?

Actual Behaviour

  • What went wrong: Execution failed for task ':compileGroovy'.

BUG! exception in phase 'semantic analysis' in source unit '/Users/adrian/Sites/hulimotors/myapp/grails-app/controllers/myapp/RestaurantController.groovy' Index 0 out of bounds for length 0

Screen Shot 2022-03-22 at 4 13 19 PM

Steps To Reproduce

  1. curl -O https://start.grails.org/myapp.zip -d profile=rest-api -d features=events,mongodb,security
  2. cd myapp
  3. grails create-domain-class Restaurant
  4. grails generate-all myapp.Restaurant
  5. Add new action method on the Controller

Screen Shot 2022-03-22 at 4 13 37 PM

  1. Add @GrailsCompileStatic to the Controller

Screen Shot 2022-03-22 at 4 17 45 PM

.

Environment Information

macOS Monterey version 12.3

openjdk version "11.0.14" 2022-01-18 OpenJDK Runtime Environment Temurin-11.0.14+9 (build 11.0.14+9) OpenJDK 64-Bit Server VM Temurin-11.0.14+9 (build 11.0.14+9, mixed mode)

Example Application

No response

Version

5.1.4

pangeaos avatar Mar 22 '22 22:03 pangeaos

Thank you for reporting the issue. I will take a look soon.

puneetbehl avatar Mar 23 '22 08:03 puneetbehl

Does the compilation succeed if you use @groovy.transform.CompileDynamic instead of @GrailsCompileStatic(TypeCheckingMode.SKIP)?

osscontributor avatar Mar 24 '22 19:03 osscontributor

Yes, it does. It's working with @groovy.transform.CompileDynamic annotation. Do We have to start using @CompileDynamic instead of @GrailsCompileStatic(TypeCheckingMode.SKIP) ? or In fact there is a bug about it in this 5.1.4 version

pangeaos avatar Mar 26 '22 17:03 pangeaos

Do We have to start using @CompileDynamic instead of @GrailsCompileStatic(TypeCheckingMode.SKIP) ?

Not necessarily, but there may not be any good reason not to do that.

or In fact there is a bug about it in this 5.1.4 version

I have not debugged it but it appears to be a bug.

osscontributor avatar Mar 28 '22 13:03 osscontributor

I've encountered the same issue upgrading a Grails app from 5.1.1 to 5.1.7 with a drain class that contains @GrailsCompileStatic(TypeCheckingMode.SKIP)

I can confirm switching to @CompileDynamic resolves the issue.

codeconsole avatar May 11 '22 17:05 codeconsole

Any update here? We just upgraded our production app to Grails 5 and this seems to be a blocker.

sagrawal31 avatar Sep 01 '22 13:09 sagrawal31

@sagrawal31 just switch @GrailsCompileStatic(TypeCheckingMode.SKIP) to @CompileDynamic

codeconsole avatar Sep 01 '22 15:09 codeconsole

Hi, @codeconsole. Thanks for the reply. Yes, for now I moved forward with @CompileDynamic. Thank you!

sagrawal31 avatar Sep 02 '22 07:09 sagrawal31

This is working fine for me till 5.3.3. BUT with 6.0.0 I am getting this issue.

BUG! exception in phase 'semantic analysis' in source unit 'MyService.groovy' Index 0 out of bounds for length 0

@CompileDynamic resolve the issue

manishkbharti avatar Jul 25 '23 10:07 manishkbharti

Any news regarding this bug? I've upgraded my app from Grails 4 to Grails 6 and I'm getting this issue too. Removing @GrailsCompileStatic or replacing it with @CompileDynamic fixes the issue but is this actually the solution?

espoir avatar Aug 30 '23 08:08 espoir