Compilation issue with JDK8, run-app, and overriding protected methods

335 views
Skip to first unread message

Tim van der Leeuw

unread,
Apr 22, 2015, 11:25:04 AM4/22/15
to grails-de...@googlegroups.com
I've run into a weird issue with the Groovy / Grails compiler in combination with Java8 the last week.

Found with Grails 2.5.0, not tested in previous versions.

When I have Groovy code which has the following pattern:

class BaseClass {
protected int foo() { return 1 }
}

class SubClass extends BaseClass {
@Override
protected int foo() { return 2 }
}

And I start my application with grails run-app and Java8, then any attempt to dynamically re-compile class SubClass will result in an error:

|Server running. Browse to http://localhost:8080/GrailsCompilationTest
  [groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
  [groovyc] /Users/gebruiker/IdeaProjects/GrailsCompilationTest/src/groovy/grailscompiletest/SubClass.groovy: 4: foo() in grailscompiletest.SubClass cannot override foo in grailscompiletest.BaseClass; attempting to assign weaker access privileges; was public
  [groovyc]  @ line 4, column 5.
......
  [groovyc]        @Override
|Compiling 1 source files
  [groovyc]        ^
.Error
  [groovyc]
|
  [groovyc] /Users/gebruiker/IdeaProjects/GrailsCompilationTest/src/groovy/grailscompiletest/SubClass.groovy: -1: $getStaticMetaClass() in grailscompiletest.SubClass cannot override $getStaticMetaClass in grailscompiletest.BaseClass; attempting to assign weaker access privileges; was public
  [groovyc]  @ line -1, column -1.
  [groovyc] 2 errors
2015-04-22 17:14:07,175 [Thread-16] ERROR compiler.GrailsProjectWatcher  - Compilation Error: startup failed:
/Users/gebruiker/IdeaProjects/GrailsCompilationTest/src/groovy/grailscompiletest/SubClass.groovy: 4: foo() in grailscompiletest.SubClass cannot override foo in grailscompiletest.BaseClass; attempting to assign weaker access privileges; was public
 @ line 4, column 5.
       @Override
       ^

/Users/gebruiker/IdeaProjects/GrailsCompilationTest/src/groovy/grailscompiletest/SubClass.groovy: -1: $getStaticMetaClass() in grailscompiletest.SubClass cannot override $getStaticMetaClass in grailscompiletest.BaseClass; attempting to assign weaker access privileges; was public
 @ line -1, column -1.
2 errors


| Compiling 1 source files
| Compiling 1 source files.
| Error 2015-04-22 17:14:08,116 [Thread-12] ERROR compiler.GrailsProjectWatcher  - Compilation Error: startup failed:
/Users/gebruiker/IdeaProjects/GrailsCompilationTest/src/groovy/grailscompiletest/SubClass.groovy: 4: foo() in grailscompiletest.SubClass cannot override foo in grailscompiletest.BaseClass; attempting to assign weaker access privileges; was public
 @ line 4, column 5.
       @Override
       ^
/Users/gebruiker/IdeaProjects/GrailsCompilationTest/src/groovy/grailscompiletest/SubClass.groovy: -1: $getStaticMetaClass() in grailscompiletest.SubClass cannot override $getStaticMetaClass in grailscompiletest.BaseClass; attempting to assign weaker access privileges; was public
 @ line -1, column -1.
2 errors


This compilation error only happens when compilation is triggered from 'grails run-app'; compiling code ahead of time with 'grails compile' there is no problem at all. However there will be a problem if I make a chance to class SubClass and it needs to be recompiled.

When doing the exact same when running on JDK7, there is no problem at all.

Looking at the code, the code is correct - the error must be in the compiler, but is triggered only under these very specific circumstances.


The problem is trivially reproduced by running:

grails create-app

Adding to BuildConfig.groovy 2 dependencies:

compile ':quartz:1.0.2'
compile ':quartz-monitor:1.0'

And then:

grails run-app

Startup will fail with error like the one above.

Alternatively you can create Groovy files for the 2 classes copy-pasted above in an empty application, run with grails run-app, and modify the SubClass and save changes to trigger re-compilation.

This problem makes dynamic development using JDK8 much harder.


Is there an issue for this already, or are the developers already aware of this problem? Should I raise in issue?
Since the issue only shows in the Grails runtime environment, I'm not sure if it's a Groovy issue or a Grails issue.

Kind regards,

--Tim

Burt Beckwith

unread,
Apr 22, 2015, 12:06:14 PM4/22/15
to grails-de...@googlegroups.com
I've been seeing the same thing and hoped that it would be better in 8u40 but it's the same. I've found that running clean and then the real command works reliably, but it's obviously slower. I had previously created a bunch of aliases for commands and added clean to some of them, so I'm using those a lot:

   alias gra='grails run-app'
   alias grac='grails clean && grails run-app'
   alias gta='grails test-app'
   alias gtac='grails clean && grails test-app'
   alias grc='grails console'
   alias grcc='grails clean && grails console'

Burt

Tim van der Leeuw

unread,
Apr 22, 2015, 12:16:58 PM4/22/15
to grails-de...@googlegroups.com
It is for me not yet fixed with 8u45 either.

Running compile first and then the real command works for me, but still cannot do dynamic recompilation of classes at runtime then, so it is really hindering development.

Strange that what works for you is 'grails clean && grails run-app' because for me that's exactly what breaks - what works for me is 'grails compile && grails run-app'.

For the moment I'm back on JDK7 for development.

--Tim

zyro

unread,
Apr 27, 2015, 4:38:51 AM4/27/15
to grails-de...@googlegroups.com
hi,

looks like this issue describes the same problem:
https://github.com/grails/grails-core/issues/619

zyro
> --
> You received this message because you are subscribed to the Google
> Groups "Grails Dev Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to grails-dev-disc...@googlegroups.com
> <mailto:grails-dev-disc...@googlegroups.com>.
> To post to this group, send email to grails-de...@googlegroups.com
> <mailto:grails-de...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/grails-dev-discuss/ae558431-4e84-4327-a1f2-772e703f7487%40googlegroups.com
> <https://groups.google.com/d/msgid/grails-dev-discuss/ae558431-4e84-4327-a1f2-772e703f7487%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages