Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotation based cleanup on methods works only when flag name is same as specified in the config #226

Open
himanshuguptan opened this issue Aug 30, 2022 · 1 comment
Labels
legacy-java Issues/PR related to older PiranhaJava implementation

Comments

@himanshuguptan
Copy link

Description:

Annotation-based cleanup looks for an exact string match on the flag name as specified in the build.gradle.
It doesn't look for the requisite enum name relationship for the specified flag name.
For example,
Case 1: Piranha:FlagName="STALE_FLAG", IsTreated = true,

public enum Experiment {
    STALE_FLAG("stale.flag"),
    OTHER_FLAG("other.flag");
    :
}

@FlagTesting(control = {"stale.flag"})
public void someMethod(...) {
  :
}

Expected: someMethod() gets deleted
Actual: someMethod() isn't deleted


Case 2: Case 1: Piranha:FlagName="stale.flag", IsTreated = true,

public enum Experiment {
    STALE_FLAG("stale.flag"),
    OTHER_FLAG("other.flag");
    :
}

@FlagTesting(control = {Experiment.STALE_FLAG})
public void someMethod(...) {
  :
}

Expected: someMethod() gets deleted
Actual: someMethod() isn't deleted


Root cause:

The likely issue is that we are simply comparing the xpFlagName value for equality with the annotation value (or one of the values in the annotation test list). While this works when both the config and the annotation usage use the same name: either the enum name or the feature flag string literal directly, it breaks in the other two possible combinations as shown above.


Fix:

Add a check where the xpFlagName not only matches the annotation value as only but either matches the value or the enum name as in the enum definition.
We could leverage a coding construct similar to these lines.

@ketkarameya ketkarameya added the legacy-java Issues/PR related to older PiranhaJava implementation label Sep 2, 2022
@ketkarameya ketkarameya changed the title [PiranhaJava] Annotation based cleanup on methods works only when flag name is same as specified in the config Annotation based cleanup on methods works only when flag name is same as specified in the config Sep 2, 2022
@ketkarameya
Copy link
Collaborator

ketkarameya commented Sep 2, 2022

@himanshuguptan can you please try to use polyglot piranha (under piranha/polyglot ) ?
This rule in polyglot Piranha kinda does what you want ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-java Issues/PR related to older PiranhaJava implementation
Projects
None yet
Development

No branches or pull requests

2 participants