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

Stubs missing imports produce unclear errors #2059

Closed
nicbec opened this issue Jun 29, 2018 · 5 comments
Closed

Stubs missing imports produce unclear errors #2059

nicbec opened this issue Jun 29, 2018 · 5 comments
Assignees

Comments

@nicbec
Copy link

nicbec commented Jun 29, 2018

Checker Framework version 2.5.2

We wanted to add a stub to our codebase that would annotate java.lang.reflect.Constructor in keeping with the Checker-Framework stubs version and the related issue below
#1365
Checker Framework stubs:
https://github.com/typetools/checker-framework/blob/460863bf1612581de76a783b4ad254b816bfe8b7/checker/jdk/nullness/src/java/lang/reflect/Constructor.java

I overlooked to add the @nonnull import to the stub. Static analysis tests that reference the stub below will compile and run, but will produce unusual errors ([assignment.type.incompatible], [return.type.incompatible], [type.argument.type.incompatible]) in classes that reference this stub that don't make it apparent that the real issue is a missing import.

It would be great to receive more clear messages for cases where stubs are missing imports.

Please let me know if other information is needed, thanks.

package java.lang.reflect;

// Missing import below.
// import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

public final class Constructor<T> extends Executable {

  public @NonNull T newInstance(Object ... initargs) throws InstantiationException,IllegalAccessException,IllegalArgumentException,InvocationTargetException {}
}
@wmdietl
Copy link
Member

wmdietl commented Jun 30, 2018

Can you try adding -AstubWarnIfNotFound as an option?

    // Whether to print warnings about types/members in a stub file
    // that were not found on the class path
    // org.checkerframework.framework.stub.StubParser.warnIfNotFound
    "stubWarnIfNotFound",

This should give you a warning about the unknown @nonnull annotation.

@nicbec
Copy link
Author

nicbec commented Jul 2, 2018

Thanks for the response. I added "-AstubWarnIfNotFound" and see warnings for other locations in our code base, but nothing referencing @nonnull, Constructor, newInstance, or java.lang.reflect. There are no new warnings between the output when I comment out/uncomment the NonNull import though there is an unclear "error: [assignment.type.incompatible] incompatible types in assignment" when the import is commented out.

@wmdietl wmdietl self-assigned this Jul 10, 2018
@nicbec
Copy link
Author

nicbec commented Jul 11, 2018

Just wanted to check in on this to see if there's anything else I should try. Please let me know, thanks.

@wmdietl
Copy link
Member

wmdietl commented Jul 16, 2018

Pull request #2072 should fix this.
Now, when using -AstubWarnIfNotFound one also gets a warning about unknown annotations.
Please give it a spin and let us know whether this solves the issue.

@nicbec
Copy link
Author

nicbec commented Jul 18, 2018

Was able to verify this fix on our build infrastructure. Thanks!

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