You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PropertiesEnhancer doesn't work when multiple setter exists #824
A simple Java class in a Play project fails to compile (DuplicateMemberException) due to the way sbt-link's PropertiesEnhancer is implemented:
class Test {
public int ByteBuffer value;
// ...
public byte [] getValue() { return value.array(); }
public Test setValue(byte [] value) { return setValue(ByteBuffer.wrap(value)); }
public Test setValue(ByteBuffer buffer) { this.value = value; return this; }
}
This kind of Java code gets automatically generated by Apache Thrift for instance. It's not an option to rewrite the class in question and it's a valid Java code anyway.
After investigating the method PropertiesEnhancer.generateAccessors() I found a way to solve the issue by explicitly asking for a setter with one parameter of the same type as the property being "enhanced":
line 97: CtMethod ctMethod = ctClass.getDeclaredMethod(setter, new CtClass [] { ctField.getType() });
instead of (currently):
line 97: CtMethod ctMethod = ctClass.getDeclaredMethod(setter);
It's quite wrong to assume that only one "setXyz" method exist in a given class. It solves the compilation error and I haven't noticed any drawbacks so far. Though I am not 100% sure what is the purpose of the property enhancer in the Play framework so I can't guarantee that this fix won't break other use cases.
Activity
jroper commentedon Aug 22, 2014
Fixed by playframework/play-enhancer#2.