Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4939

groovyc compilation problem for return values with generics

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8.1
    • 1.8.2, 1.9-beta-3, 1.7.11
    • Compiler
    • None

    Description

      Hi I have following code which was ok for groovy 1.8.0 but after updating to groovy 1.8.1 I have failed compilation

      MessagingTask.groovy
      class MessagingTask<T extends Serializable> {
      
        private static final long serialVersionUID = -5533069690405593263L;
      
        Long id
        String messageId
        String inDestination
        String outDestination
        MessagingTaskType messageType
        T messagePayload
      
        public String toString() {
          return "Task{" +
                  "id=" + id +
                  ", messageId='" + messageId + '\'' +
                  ", inDestination='" + inDestination + '\'' +
                  ", outDestination='" + outDestination + '\'' +
                  ", messageType='" + messageType + '\'' +
                  ", messagePayload=" + messagePayload +
                  '}';
        }
      }
      
      MessagingTaskDatabase.groovy
      class MessagingTaskDatabase {
      
          public List<MessagingTask<OutMessage>> loadOutMessage() {
              return new ArrayList<MessagingTask<OutMessage>>();
          }
      
      }
      
      SomeClient.java
      List<MessagingTask<OutMessage>> messagingTasks = taskDatabase.loadOutMessage();
      

      And the compile log:

          [mkdir] Created dir: /home/sargis/projects/twm_v3/trunk/twm_v3/accounting/Server/classes
        [groovyc] Compiling 185 source files to /home/sargis/projects/twm_v3/trunk/twm_v3/accounting/Server/classes
        [groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
        [groovyc] Compile error during compilation with javac.
        [groovyc] /home/sargis/projects/twm_v3/trunk/twm_v3/accounting/Server/src/com/webbfontaine/twm/accounting/epaylog/scheduler/SendingScheduler.java:46: incompatible types
        [groovyc] found   : java.util.List<com.webbfontaine.twm.accounting.epaylog.emess.task.MessagingTask>
        [groovyc] required: java.util.List<com.webbfontaine.twm.accounting.epaylog.emess.task.MessagingTask<com.webbfontaine.twm.accounting.epaylog.emess.core.OutMessage>>
        [groovyc]         List<MessagingTask<OutMessage>> messagingTasks = taskDatabase.loadOutMessage();
        [groovyc]                                                                                     ^
        [groovyc] Note: Some input files use unchecked or unsafe operations.
        [groovyc] Note: Recompile with -Xlint:unchecked for details.
        [groovyc] 1 error
        [groovyc] 
        [groovyc] 
        [groovyc] 1 error
      

      But if I remove generic type parameters from return and compilation is ok

      public List loadOutMessage() {
          return new ArrayList<MessagingTask<OutMessage>>();
      }
      

      Attachments

        1. groovyc-test.tar.gz
          3 kB
          Sargis Harutyunyan

        Activity

          People

            paulk Paul King
            armsargis Sargis Harutyunyan
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: