In my Result
class I annotated with @IntDef first integer parameter in newInstance()
method like this:
public class Result {
public static final int SUCCESS = 0;
public static final int FAIL = 1;
public static final int UNKNOWN = 2;
// ...
private Result(@Status int status, Uri uri) {
mStatus = status;
mUri = uri;
}
public static Result newInstance(@Status int status, Uri uri) {
return new Result(status, uri);
}
@Retention(RetentionPolicy.SOURCE)
@IntDef({ SUCCESS, FAIL, UNKNOWN })
@interface Status {}
}
Next, in my Utils
class I invoke that method and pass correct constant as parameter. I ensure that I use specific set of constants like this:
public static Result foo() {
// ...
return Result.newInstance(Result.SUCCESS, contentUri); // line 45
}
But lint fails the build with Security error
"WrongConstant: Incorrect constant"
../../src/main/java/my/package/Utils.java:45: Must be one of: 0, 1, 2
I know that this error can be simply suppressed. But I'd like to know what's wrong with my code? Or maybe it's another issue?