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

Cannot call private constructor from closures with @CompileStatic

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.7, 2.5.x
    • Fix Version/s: 2.4.8
    • Component/s: Static compilation
    • Labels:
      None
    • Environment:
      Ubuntu 16.04
      openjdk version "1.8.0_91"

      Description

      Test.groovy
      import groovy.transform.CompileStatic
      
      @CompileStatic
      interface Handler<E> {
          void handle(E event)
      }
      
      @CompileStatic
      class Person {
      
          final String name
      
          // marking this method as 'protected' will fix the issue
          private Person(String name) {
              this.name = name
          }
      
          static void load(String name, Handler<Person> handler) {
              Thread.start {
                  Person person = new Person(name)
                  handler.handle(person)
              }
          }
      
      }
      
      Person.load('John') { Person p ->
          println p.name
      }
      
      

      Error:

      Test.groovy: 20: Cannot call private constructor for Person from class Person$_load_closure1 @ line 20, column 20.
      Person person = new Person(name)
      ^

      1 error

        Attachments

        Issue Links

          Activity

            People

            • Assignee:
              shils Shil Sinha
              Reporter:
              cazacugmihai Cazacu Mihai

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment