-
Notifications
You must be signed in to change notification settings - Fork 299
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
External Library Models: Adding support for @Nullable Method parameters #1006
External Library Models: Adding support for @Nullable Method parameters #1006
Conversation
I wanted to summarize some thoughts and issues on how to move forward with this PR, to possibly get some help. As part of #950, we need a way to store in an But this change, in turn, caused problems for JarInfer, as its logic for storing stub files still uses simple type names, but we are using shared parsing logic for stub files. (At least I think that's the issue; @akulk022 can you clarify why you had to make the change in I propose the following:
A question becomes, what should we do with old @lazaroclapp do you have any thoughts / feedback on this? |
@msridhar I made the change on line 246 in |
I see. I think this is in fact an argument for unifying the logic between
these two handlers and only having one handler. Right now the code
structure is quite confusing and leading to problems. Maybe we should do
some refactoring and unification in a separate PR even before landing this
one.
…On Jul 25, 2024 at 02:25:10, Abhijit Kulkarni ***@***.***> wrote:
@msridhar <https://github.com/msridhar> I made the change on line 246 in
InferredJARModelsHandler.java because the existing test case
libraryModelNullableReturnsTest was failing since argAnnotCache now
contains fully qualified names for the parameters and we were not able to
perform a lookup in the cache after getting a simple type name. Do you
think we should separate out the logic for handling @nullable returns for
Inferred JAR Models and Library Models?
—
Reply to this email directly, view it on GitHub
<#1006 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABPEUIETSC2LUVSLMLXFCLZOC77NAVCNFSM6AAAAABLIZBTHSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBZHA4DCMRTHE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I agree with the approach above, and we can even just error out if the
This will imply regenerating Does this seem reasonable? |
Thanks @lazaroclapp! All sounds good to me. My only concern is the following:
Thinking more about this, will this involve building each of those SDK versions from source? That may be moderately to extremely painful...we can look into it. But I agree it's the best solution and we should see if we can do it. |
I'd like to unblock this PR. I propose we go ahead and evolve the
@akulk022 WDYT? If you think it's ok you can go ahead with 1 as a separate PR (or I can potentially look into it). |
Update here is that it's hard to get rid of |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1006 +/- ##
============================================
+ Coverage 87.23% 87.54% +0.31%
- Complexity 2129 2138 +9
============================================
Files 83 83
Lines 6965 7003 +38
Branches 1356 1367 +11
============================================
+ Hits 6076 6131 +55
+ Misses 458 451 -7
+ Partials 431 421 -10 ☔ View full report in Codecov by Sentry. |
This is in preparation for #1006. When working on that PR I realized we really need some unit tests to more easily debug various scenarios (right now all we have are integration tests). Plus this will make our code coverage reports more useful. This adds some infrastructure for unit tests and a couple of basic tests; we will add more as we go. Also fix a couple minor issues in `LibraryModelGenerator`.
# Conflicts: # library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking promising! I have a few comments
jar-infer/jar-infer-lib/src/test/java/com/uber/nullaway/jarinfer/JarInferTest.java
Show resolved
Hide resolved
private final Map<String, Set<Integer>> nullableUpperBounds; | ||
// TODO this is sketchy! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this comment 🙂 I think we need to do for arrays whatever JarInfer is now doing. We should also add integration tests.
ResolvedType returnType = md.getReturnType(); | ||
if (returnType.isReferenceType()) { | ||
return returnType.asReferenceType().getQualifiedName().toString(); | ||
} else if (returnType.isArray()) { | ||
return ARRAY_RETURN_TYPE_STRING; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably this needs to be updated
.../library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java
Show resolved
Hide resolved
"@NullMarked", | ||
"public class NullMarked{", | ||
"//Only this class should appear under null marked classes", | ||
"}", | ||
"class NotNullMarked{", | ||
"}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation
}; | ||
ImmutableSet<String> expectedNullMarkedClasses = ImmutableSet.of("NullMarked"); | ||
runTest( | ||
"NullableUpperBound.java", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird file name. Choose one of the classes actually included in the file.
...rary-model-generator/src/test/java/com/uber/nullaway/libmodel/LibraryModelGeneratorTest.java
Show resolved
Hide resolved
nullaway/src/main/java/com/uber/nullaway/handlers/InferredJARModelsHandler.java
Show resolved
Hide resolved
@@ -1287,20 +1287,23 @@ private <T> NameIndexedMap<T> makeOptimizedLookup( | |||
/** Constructs Library Models from stubx files */ | |||
private static class ExternalStubxLibraryModels implements LibraryModels { | |||
|
|||
@SuppressWarnings("unused") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get rid of suppression or delete the field
if (index >= 0) { | ||
mapBuilder.put(methodRef(className, methodName), index); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to check if index >= 0
? And don't we need to check if the annotation is @Nullable
? This seems to add something to the map for any annotation. If we can, we should add a test so that if the annotation is @NonNull
we skip it (not sure if this is possible).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the index>=0
check because argAnnotCache
holds the annotation for the return of the method with the index -1
and for all the parameter annotations with their respective indices, should this have been handled in a different way? I can add the @Nullable
check and the corresponding test case.
…nto library_model_nullable_params
…nto library_model_nullable_params
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting pretty close!
* The file magic number for version 1 .astubx files. It should be the first four bytes of any | ||
* compatible .astubx file. | ||
*/ | ||
private static final int VERSION_1_FILE_MAGIC_NUMBER = 481874642; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lazaroclapp should we have a separate magic number (for the astubx file format) and version number?
...rary-model-generator/src/test/java/com/uber/nullaway/libmodel/LibraryModelGeneratorTest.java
Show resolved
Hide resolved
...rary-model-generator/src/test/java/com/uber/nullaway/libmodel/LibraryModelGeneratorTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this contribution @akulk022!
With these changes we can read annotations from method parameters and use them with our External Library Models in the following manner.
Externally annotated code example:
In order to accomplish this, we had to change the
astubx
format to use fully-qualified names for argument and return types. This also required changes to JarInfer. These are backward-incompatible changes, so we have changed the magic number forastubx
files.