[
https://issues.apache.org/jira/browse/GROOVY-12427?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King resolved GROOVY-12427.
--------------------------------
Fix Version/s: 7.0.0-alpha-1
6.0.1
Resolution: Fixed
> Joint compilation stub declares a precompiled trait's static methods "static
> abstract" on implementing classes
> --------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12427
> URL: https://issues.apache.org/jira/browse/GROOVY-12427
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 6.0.0
> Reporter: Mattias Reichel
> Assignee: Paul King
> Priority: Major
> Fix For: 7.0.0-alpha-1, 6.0.1
>
>
> When a Groovy class implements a trait that comes precompiled (from a jar or
> another module), and a Java source in the same joint compilation references
> that class, the Java stub generated for the class declares the trait's static
> methods as {{static abstract}} with a body. javac rejects the stub.
> This compiles on Groovy 5.0.6, 5.1.2 and 5.1.3 and fails on 6.0.0. It does
> not happen when the trait is compiled in the same joint compilation.
> h3. Steps to reproduce
> {code:title=trait/Named.groovy}
> trait Named {
> static String describe() { 'named' }
> }
> {code}
> {code:title=src/Person.groovy}
> class Person implements Named { }
> {code}
> {code:title=src/UsesPerson.java}
> public class UsesPerson {
> Person person = new Person();
> }
> {code}
> {noformat}
> mkdir lib out
> java -cp groovy-6.0.0.jar org.codehaus.groovy.tools.FileSystemCompiler -d lib
> trait/Named.groovy
> java -cp groovy-6.0.0.jar org.codehaus.groovy.tools.FileSystemCompiler -cp
> lib -d out -j src/Person.groovy src/UsesPerson.java
> {noformat}
> h3. Expected
> Compilation succeeds, as on Groovy 5.1.3.
> h3. Actual
> {noformat}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
> failed:
> Compile error during compilation with javac.
> <stub dir>/Person.java:8: error: illegal combination of modifiers: abstract
> and static
> @org.codehaus.groovy.transform.trait.Traits.Implemented() public static
> abstract java.lang.String describe() { return null; }
>
> ^
> <stub dir>/Person.java:2: error: Person is not abstract and does not override
> abstract method describe() in Person
> public class Person
> ^
> 2 errors
> {noformat}
> h3. Notes
> The stubs, kept with {{jointCompilationOptions = [stubDir: ..., keepStubs:
> true]}}, differ only in that method. On 5.1.3 the stub for {{Person}} has no
> {{describe()}}. On 6.0.0 it contains:
> {code:java}
> @org.codehaus.groovy.transform.trait.Traits.Implemented() public static
> abstract java.lang.String describe() { return null; }
> {code}
> The method seems to be copied from the precompiled trait with its
> {{abstract}} modifier kept. This may be related to the stub changes in
> GROOVY-11976, and to GROOVY-11899, which covered a Java source referencing
> the trait itself.
> Found while moving Apache Grails to Groovy 6: a Java source that references a
> Groovy class implementing {{grails.validation.Validateable}} or a GORM entity
> trait no longer compiles. The workaround is to implement the static methods
> on the class explicitly.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)