Skip to content

Setter method fails to assign boolean field when parameter name matches getter name (isPropertyName()) #2590

@zahi1990

Description

@zahi1990

Product/Component: EclipseLink JPA

Observed Behavior (The Bug): A JPA entity using property access for a boolean field experiences a failure in assignment when the setter method's parameter is named identically to the conventional getter method name. Although the setter is called successfully (e.g., in a @PrePersist listener) with a value of true, the class field remains false after the assignment line. This indicates a potential conflict or malfunction during the framework's introspection of the method signature.

Expected Behavior: The simple Java assignment within the setter (this.bool = isBool;) should execute successfully regardless of the parameter name, provided the parameter does not shadow the field name (which is the case here). The class field should be correctly updated.

To Reproduce

  • EclipseLink version: 4.0.1
  • Java/JDK version: 17
  1. Create a simple Jakarta EE project with EclipseLink as the JPA provider.
  2. Define an entity (e.g., MyEntity) with a boolean field (bool) and standard accessors.
  3. Name the boolean getter method isBool().
  4. Name the boolean setter method's parameter isBool.
  5. Call the setter via a listener (e.g., @PrePersist) or directly with a value of true.
  6. Observe the field value after assignment (e.g., via logging or debugger).
@Entity
public class MyEntity {
    @Id
    private Long id;
    private boolean bool; 
    // Getter: Naming convention is 'isBool()'
    public boolean isBool() { return bool; }
    // Setter: Parameter name 'isBool' matches getter name
    public void setBool(boolean isBool) {
        System.out.println("Param Value: " + isBool); // Prints: true
        this.bool = isBool; // <-- Assignment Fails!
        System.out.println("Field Value: " + this.bool); // Prints: false
    }
}

Workaround
The issue is resolved by simply changing the setter method's parameter name to anything other than the getter's name prefix (e.g., setBool(boolean value)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions