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

add Nonnull and Nullable annotations to ContextRun function #206

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions subprojects/parseq/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ configurations {
}

dependencies {
compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
Copy link
Contributor

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 add this findbugs dependency? As we discussed earlier, I hope that this annotation should not depend on one particular static analysis tools.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javax.annotation package is part of findbugs. This is just lib import, we don't need to run findbugs to use these annotations but if you're not willing to import lib as well then this change can't be made.
In my opinion importing this lib should not have any impact and it's a very standard practice.
let me know what you think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mchen07 bump

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. I am still struggling whether we should introduce such @nullable annotation where different IDE may have different support (for example, IntelliJ has its own @nullable support, which is different from javax.annotation, see https://www.jetbrains.com/help/idea/nullable-and-notnull-annotations.html), or instead we should use java Optional to indicate this, where we don't depend on the implementation of static code analysis tool.

Copy link
Contributor Author

@hiteshsharma hiteshsharma Feb 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mchen07 documentation doesn't mentions it (probably old) but IntelliJ supports it. You can go to Intellij Preferences -> Editor -> Inspections -> Java -> Probable bugs -> @NotNull/@Nullable problems -> Configure annotations
There you can see javax.annotation.Nullable and Notnull too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip @hiteshsharma. Have you seen this: spotbugs/spotbugs#180? Recently spotbugs is preferred over findBugs, will this have side effect on that trend?

compile group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.8.8'
compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.8.8'
compile group: "org.slf4j", name: "slf4j-api", version: "1.7.25"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;

import javax.annotation.Nonnull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -184,7 +185,8 @@ default <R> Task<R> apply(final String desc, final PromisePropagator<T, R> propa
* @param func function to be applied to successful result of this task.
* @return a new task which will apply given function on result of successful completion of this task
*/
default <R> Task<R> map(final String desc, final Function1<? super T, ? extends R> func) {
@Nonnull
default <R> Task<R> map(@Nonnull final String desc, @Nonnull final Function1<? super T, ? extends R> func) {
ArgumentUtil.requireNotNull(func, "function");
return apply(desc, new PromiseTransformer<T, R>(func));
}
Expand All @@ -193,7 +195,8 @@ default <R> Task<R> map(final String desc, final Function1<? super T, ? extends
* Equivalent to {@code map("map", func)}.
* @see #map(String, Function1)
*/
default <R> Task<R> map(final Function1<? super T, ? extends R> func) {
@Nonnull
default <R> Task<R> map(@Nonnull final Function1<? super T, ? extends R> func) {
return map("map: " + _taskDescriptor.getDescription(func.getClass().getName()), func);
}

Expand Down