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

@EnsuresNonNullIf produce contracts.conditional.postcondition error #6288

Open
is-ivanov opened this issue Nov 8, 2023 · 0 comments
Open
Assignees

Comments

@is-ivanov
Copy link

I have two methods in utilityclass

    @EnsuresNonNullIf(expression = "#1", result = true)
    public static boolean isOne(@Nullable Integer value) {
        return Objects.equals(value, 1);
    }

    @EnsuresNonNullIf(expression = "#1", result = true)
    public static boolean isOneOrZero(@Nullable Integer value) {
        return Objects.equals(value, 0) || Objects.equals(value, 1);
    }

After I added annotation @EnsuresNonNullIf(expression = "#1", result = true) I get the errors

 error: [contracts.conditional.postcondition] conditional postcondition is not satisfied when isOne returns true.
        return Objects.equals(value, 1);
        ^
  found   : value is @Nullable
  required: value is @NonNull
  
  error: [contracts.conditional.postcondition] conditional postcondition is not satisfied when isOneOrZero returns true.
        return Objects.equals(value, 0) || Objects.equals(value, 1);
        ^
  found   : value is @Nullable
  required: value is @NonNull

Objects.equals -> from jdk package java.util

I added jdk.astub file

import org.checkerframework.checker.nullness.qual.Nullable;

package java.util;

public final class Objects {
    public static boolean equals(@Nullable Object a, @Nullable Object b);
}

but it doesn't help.

@smillst smillst self-assigned this Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants