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

Hack NullAway LibraryModels generator MVP POC #2

Open
1 of 9 tasks
vorburger opened this issue Aug 20, 2024 · 2 comments
Open
1 of 9 tasks

Hack NullAway LibraryModels generator MVP POC #2

vorburger opened this issue Aug 20, 2024 · 2 comments

Comments

@vorburger
Copy link
Member

vorburger commented Aug 20, 2024

The goal of this issue would be to explore hacking a converter from annotated Java sources to a NullAway LibraryModels generator MVP POC.

Use case / application would be for / driven by enola-dev/enola#845 (and possibly also using NullAway e.g. for my https://github.com/vorburger/ch.vorburger.exec or https://github.com/vorburger/ch.vorburger.fswatch or https://github.com/MariaDB4j/MariaDB4j).

Approach/steps planned would be to:

https://github.com/javaparser/javaparser, and/or it's apparent (?) fork https://github.com/eisop/stubparser, used by (?) https://github.com/typetools/annotation-tools may be of interest - although I don't yet fully understand if any of that is even needed... what's wrong with plain simple Java reflection?!

Re. uber/NullAway#1024

/CC @cpovirk FYI

@cpovirk
Copy link

cpovirk commented Aug 21, 2024

FWIW, the Checker Framework groups (EISOP + Typetools) are trying to move off JavaParser IIUC, as they've had issues:

Their likely replacement is https://github.com/plume-lib/javac-parse/blob/main/src/main/java/org/plumelib/javacparse/JavacParse.java, which contains the same basic boilerplate as various similar tools use (example).

As for reflection: If you can actually compile the annotated Java sources, then that could work fine AFAIK. (Maybe bugs around type annotations are more likely for reflection than for build tools, but I don't know. I at least doubt you'd have significant issues for annotations on "root" locations (e.g., fields and method return types, as opposed to type arguments inside those).) I think we ended up with our approach in part because we were interested in annotations for the JDK, which might be trickier to build? I don't actually remember the details of that discussion, if even I heard most of them in the first place. (I do think that trying to do the job with only a "parser" is a bit sketchy: You really want the deps of the classes to be available, I think. But apparently they mostly get away with it.)

@msridhar
Copy link

A couple of thoughts / questions.

  • By default, NullAway treats calls to unannotated code optimistically; it assumes methods in this code always accept null and never return null. So, even when adopting NullAway, you may not observe issues related to the third-party libraries (since the issues are likely to be missed errors, not false positives).
  • Do the annotations for the library model originate in Java source code, or some other type of file (like the EEA files)? If it's Java source code, we're working on a converter from Java source annotations to astubx as part of our efforts to consume the https://github.com/jspecify/jdk annotations in NullAway. (We are using JavaParser for now.) Once we're done we could put that code in a separate Maven artifact and perhaps you could re-use it for other libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants