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

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

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 2.1.9, 2.2.1, 2.3.0, 2.4.0-rc-1
    • Fix Version/s: 2.4.8
    • Component/s: Static compilation
    • Labels:
      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

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

                Dates

                • Created:
                  Updated:
                  Resolved: