-
Notifications
You must be signed in to change notification settings - Fork 300
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
JSpecify: Reason about nullability of reads from arrays #875
Changes from 11 commits
4a53079
0524a6e
627f64e
e429aba
4b640ef
0af1d28
08e79e9
bdda3ae
08aac83
8cfd282
964d6b0
2ea7d86
87d3cc6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,8 +31,10 @@ | |
import com.google.errorprone.suppliers.Suppliers; | ||
import com.google.errorprone.util.ASTHelpers; | ||
import com.sun.source.tree.MethodInvocationTree; | ||
import com.sun.tools.javac.code.Attribute; | ||
import com.sun.tools.javac.code.Symbol; | ||
import com.sun.tools.javac.code.Type; | ||
import com.sun.tools.javac.code.TypeAnnotationPosition; | ||
import com.sun.tools.javac.code.TypeTag; | ||
import com.uber.nullaway.CodeAnnotationInfo; | ||
import com.uber.nullaway.Config; | ||
|
@@ -794,9 +796,32 @@ | |
public TransferResult<Nullness, NullnessStore> visitArrayAccess( | ||
ArrayAccessNode node, TransferInput<Nullness, NullnessStore> input) { | ||
ReadableUpdates updates = new ReadableUpdates(); | ||
|
||
setNonnullIfAnalyzeable(updates, node.getArray()); | ||
// this is unsound | ||
return updateRegularStore(defaultAssumption, input, updates); | ||
|
||
Nullness resultNullness = defaultAssumption; | ||
|
||
// TODO: export to utility method | ||
if (config.isJSpecifyMode()) { | ||
Symbol arraySymbol = ASTHelpers.getSymbol(node.getArray().getTree()); | ||
if (arraySymbol != null) { | ||
boolean isElementNullable = false; | ||
for (Attribute.TypeCompound t : arraySymbol.getRawTypeAttributes()) { | ||
for (TypeAnnotationPosition.TypePathEntry entry : t.position.location) { | ||
if (entry.tag == TypeAnnotationPosition.TypePathEntryKind.ARRAY) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above, check for |
||
isElementNullable = true; | ||
break; | ||
} | ||
} | ||
Check warning on line 815 in nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPathNullnessPropagation.java Codecov / codecov/patchnullaway/src/main/java/com/uber/nullaway/dataflow/AccessPathNullnessPropagation.java#L815
|
||
if (isElementNullable) { | ||
resultNullness = Nullness.NULLABLE; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return updateRegularStore(resultNullness, input, updates); | ||
} | ||
|
||
@Override | ||
|
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 think we need to check whether the annotation is actually
@Nullable
. This just checks for the presence of some annotation. And yes this logic should be extracted to a utility method.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.
Addressed!