Comments (10)
Similarly - supporting jetbrains' @Contract
annotations could help here
from nullaway.
Maybe something like @ImpliesNonNull(when = true, param = 0)
from nullaway.
NullAway does not reason across procedure boundaries about nullness checks, so it won't be able to prove this safe. If you frequently use the getIfReady
method to check for nullness, you can handle this with a custom library model; see #51
Closing, but please re-open if you have more questions
from nullaway.
Re-opening as we should support this case with an annotation. The user should be able to write something like:
@RetTrueImpliesNonNullParam(0)
static boolean isReady(@Nullable CompletableFuture<?> future) {
return (future != null) && future.isDone()
&& !future.isCompletedExceptionally()
&& (future.join() != null);
}
The annotation means that if the function returns true, the 0th parameter future
cannot be null. We also want @RetFalseImpliesNonNullParam
or the like (naming TBD). We could trust the annotations at first but maybe eventually check them.
from nullaway.
Actually, for an Iterator I think it should be params
with an array of strings. For example, I'd like to assert that key
and value
are non-null if hasNext()
is true.
public Entry<K, V> next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
Entry<K, V> entry = new WriteThroughEntry<>(cache, key, value);
removalKey = key;
value = null;
next = null;
key = null;
return entry;
}
Though that would best be if suppressed on the call-site, which isn't always possible, so It definitely messy.
from nullaway.
I think the hasNext
example is about non-nullness of fields of the receiver object, yes? We could support that too, though it'd take a bit more work.
from nullaway.
Yep, they are different cases of a similar problem. Thanks!
from nullaway.
Ok, so, @msridhar, question: Are we currently shipping any support library for NullAway
where we could put this new custom annotation? If not, I think we should, together with the castToNonNull
method. As for @ImpliesNonNull
, I think it can take either an array of arguments or an array of access paths. The later case would probably come at a performance cost, but we can make sure we only pay it when people use this annotation. We can talk more about this 1:1.
from nullaway.
Thanks you!
from nullaway.
To be clear, we don't yet support cases involving fields like the one @ben-manes outlined here. I'll open a follow-up task on that.
from nullaway.
Related Issues (20)
- jdk Files false positive/wrong line HOT 3
- Update JSpecify package in docs HOT 1
- The combination of JSpecify + Lombok does not seem to work well HOT 6
- Method references of nullable instances are not detected HOT 1
- Detected NPE causes EP's Var rule to go nuts. HOT 5
- Validation of null in a switch-case with pattern matching does not work as expected. HOT 1
- False positive warning on switch statements with case null
- Build failure : 'options.compilerArgumentProviders.errorprone$0.name' is missing an input or output annotation. HOT 1
- Support org.apache.commons.lang3.StringUtils.isNotEmpty HOT 3
- Support for `collect()` in Streams API HOT 4
- Control flow analysis fails within a stream collector HOT 5
- Validation of null in a method used in a boolean expression does not work as expected. HOT 1
- `if (Foo.this.bar != null)` in nested class not properly analyzed HOT 1
- Rename the Jar Infer Flags `JarInferEnabled`,`JarInferUseReturnAnnotations`
- Variable checked non-null outside a `forEach` or `Stream` lambda triggers an error HOT 13
- `if` statement on a boolean does not prevent a dereferenced nullable error HOT 1
- Null `if` check and failing function to taken in account HOT 2
- Extract methods in StreamNullabilityPropagator HOT 1
- ignoring generic Nullable on Supplier HOT 14
- Published NonNull Present HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nullaway.