Uploaded image for project: 'Magnolia Groovy Module'
  1. Magnolia Groovy Module
  2. MGNLGROOVY-168

Invalid duplicate class definition

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 2.5.4, 2.6
    • 2.5.3
    • None
    • None
    • Yes
    • Basel 120, Basel 121
    • 2

      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.

        Acceptance criteria

              fgrilli Federico Grilli
              fgrilli Federico Grilli
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Bug DoR
                  Task DoD