Skip to content

Getter with side-effect mutation in AbstractEarModule.getBundleDir() and getLibDir() #516

Description

@elharo

Description

In AbstractEarModule.java:240-251, the getters getBundleDir() and getLibDir() silently mutate instance state:

public String getBundleDir() {
    bundleDir = cleanArchivePath(bundleDir);  // modifies field
    return bundleDir;
}
public String getLibDir() {
    libDirectory = cleanArchivePath(libDirectory);
    return libDirectory;
}

Getters modifying instance fields is surprising and makes debugging harder. While cleanArchivePath is idempotent, the side-effect could cause subtle bugs if a subclass overrides getBundleDir() while the parent field gets modified elsewhere.

Expected behavior

Use a local variable instead of assigning to the field:

public String getBundleDir() {
    return cleanArchivePath(bundleDir);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions