Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4.3
-
None
-
OSX Yosemite, JDK 1.8.0_25
Description
Calling a statically compiled, non-void setter for a property will result in a NoSuchMethodError being thrown at runtime. There is no error if the setter corresponds to a field.
Example:
import groovy.transform.CompileStatic @CompileStatic class A { int prop private int field A setProp(int prop) { this.prop = prop this } A setField(int field) { this.field = field this } static void main(String[] args) { A a = new A() a.setField(1) // ok a.setProp(1) //throws NoSuchMethodError at runtime } } A a = new A() a.setField(1) //ok a.setProp(1) //throws NoSuchMethodError
The problem appears to be in the `makeSetProperty` method of `StaticTypesBinaryExpressionMultiTypeDispatcher`, where only void setter methods of a ClassNode are looked up.
The most recent version of Groovy where this isn't an issue is 2.3.3.