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

Unable to call private method/constructor from static inner class with @CompileStatic

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 2.1.9, 2.2.1, 2.3.0, 2.4.0-rc-1
    • 2.4.8
    • Static compilation
    • None

    Description

      @groovy.transform.CompileStatic
      class Client {
      	static class Builder {
      		int a
      
      		Client build() {
      			return new Client(a)
      		}
      	}
      
      	int b
      	private Client(int b) {
      		this.b = b
      	}
      }
      
      final client = new Client.Builder(a : 1).build()
      println client.b
      

      produces the error

      Caught: java.lang.IllegalAccessError: tried to access method Client.<init>(I)V from class Client$Builder
      java.lang.IllegalAccessError: tried to access method Client.<init>(I)V from class Client$Builder
      	at Client$Builder.build(test1.groovy:7)
      	at Client$Builder$build.call(Unknown Source)
      	at test1.run(test1.groovy:17)
      

      but produces the correct result (1), without the @CompileStatic

      Attachments

        Issue Links

          Activity

            People

              shils Shil Sinha
              acourtneybrown Adam Brown
              Votes:
              3 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: