PropertiesEnhancer doesn't work when multiple setter exists · Issue #824 · playframework/playframework · GitHub
Skip to content

PropertiesEnhancer doesn't work when multiple setter exists #824

Closed

Description

@jroper

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.

Cheers.
@gissues:{"order":89.74358974358972,"status":"backlog"}

Activity

  1. self-assigned this
    on Aug 22, 2014
  2. jroper commented on Aug 22, 2014

    @jroper
    MemberAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions