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

Spurious compiler warnings due to @Nullable annotations #9

Open
akirschbaum opened this issue May 20, 2014 · 2 comments
Open

Spurious compiler warnings due to @Nullable annotations #9

akirschbaum opened this issue May 20, 2014 · 2 comments
Assignees
Milestone

Comments

@akirschbaum
Copy link

Recent Grappa versions annotate Var.get() with @nullable. While technically correct, this causes spurious warnings in parsers:

Rule r() {
    Var<String> v = new Var<>();
    return sequence('x', v.set("x"), 'y', f(v.get()));
}

In this code fragment the function f(String) cannot take a @nonnull parameter even if the actual value returned by v.get() is never null.

As a solution, a new function Var.getNonnull() could be added to Reference:

@Nonnull
public T getNonnull() {
    if (value == null) {
        throw new IllegalStateException();
    }
    return value;
}
@fge fge self-assigned this May 20, 2014
@fge fge added this to the 1.0.0 milestone May 20, 2014
fge added a commit that referenced this issue May 20, 2014
Reference allows for null, which sucks. This will certainly change for 1.1 (with
the current Reference renamed to NullableReference).

However, since JSR 305 is used, .get() is annotated as @nullable and this causes
concerns for people who emit warnings at compile time when this annotation is
present.

Introduce a .getNonnull() method which is annotated as @nonnull; if the
underlying value is null, throw an IllegalStateException.

Fixes issue #9.
@fge
Copy link
Owner

fge commented May 20, 2014

Good idea... Done.

@fge fge closed this as completed May 20, 2014
@fge
Copy link
Owner

fge commented May 20, 2014

Actually, I'll leave this issue open until the next version is out.

@fge fge reopened this May 20, 2014
@fge fge modified the milestones: 1.0.0-beta.10, 1.0.0 May 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants