[MGNLGROOVY-168] Invalid duplicate class definition Created: 02/Nov/17  Updated: 10/Nov/17  Resolved: 08/Nov/17

Status: Closed
Project: Magnolia Groovy Module
Component/s: None
Affects Version/s: 2.5.3
Fix Version/s: 2.5.4, 2.6

Type: Bug Priority: Major
Reporter: Federico Grilli Assignee: Federico Grilli
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Documentation update required:
Yes
Date of First Response:
Sprint: Basel 120, Basel 121
Story Points: 2

 Description   

To reproduce the issue simply add my.commands.GroovyMailCommand (a sample class provided by ourselves) as a command class to any module in JCR config tree. This will trigger Groovy recompilation and the following exception will ensue

2017-11-01 15:34:48,301 ERROR a.module.groovy.support.classes.GroovyClassFactory: Could not compile my.commands.GroovyMailCommand with Groovy:
startup failed:
magnolia-repository://scripts/my/commands/GroovyMailCommand: 7: Invalid duplicate class definition of class my.commands.GroovyMailCommand : The source magnolia-repository://scripts/my/commands/GroovyMailCommand contains at least two definitions of the class my.commands.GroovyMailCommand.
One of the classes is an explicit generated class using the class statement, the other is a class generated from the script body based on the file name. Solutions are to change the file name or to change the class name.
 @ line 7, column 1.
   public class GroovyMailCommand extends MgnlCommand {
   ^
1 error
...

This happens because the source mixes class declarations and script parts. In particular it contains class GroovyMailCommand, which we enforce since a Groovy source which is not explicitly set as script must contain a class declaration matching the file name (this, along with package name, guarantees the uniqueness of the class name), and some script statements. When the class is used in JCR config, as in our case, the source is recompiled and the scripting part automatically turned by the Groovy compiler into a class whose name matches that of the file. Hence the duplicate class definition error.



 Comments   
Comment by Christoph Meier [ 03/Nov/17 ]

Thnx for the info.
fgrilli - It has changed since which mgnl-groovy version?
Only on the one which goes out with 5.6 ?

Comment by Federico Grilli [ 03/Nov/17 ]

cmeier this also concerns Groovy 2.5.4/ Magnolia 5.5.8. Thank you.

Generated at Mon Feb 12 05:56:15 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.