-
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
Add Guava 31+ support by treating @ParametricNullness as @Nullable #629
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
75a5427
Add Guava 31+ support by treating @ParametricNullness as @Nullable
lazaroclapp 5d6c1c9
Minor fix
lazaroclapp 76b23de
Un-time-travel build.gradle
lazaroclapp 8c5a38d
Build/CI fixes, incl. code cov
lazaroclapp 78d06d0
CI fixes.
lazaroclapp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (C) 2022. Uber Technologies | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
plugins { | ||
id 'java-library' | ||
id 'nullaway.jacoco-conventions' | ||
} | ||
|
||
// We need this separate build target to test newer versions of Guava | ||
// (e.g. 31+) than that which NullAway currently depends on. | ||
|
||
dependencies { | ||
testImplementation project(":nullaway") | ||
testImplementation deps.test.junit4 | ||
testImplementation(deps.build.errorProneTestHelpers) { | ||
exclude group: "junit", module: "junit" | ||
} | ||
testImplementation deps.build.jsr305Annotations | ||
testImplementation "com.google.guava:guava:31.1-jre" | ||
} | ||
|
||
test { | ||
maxHeapSize = "1024m" | ||
if (!JavaVersion.current().java9Compatible) { | ||
jvmArgs "-Xbootclasspath/p:${configurations.errorproneJavac.asPath}" | ||
} else { | ||
// to expose necessary JDK types on JDK 16+; see https://errorprone.info/docs/installation#java-9-and-newer | ||
jvmArgs += [ | ||
"--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", | ||
"--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", | ||
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", | ||
"--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", | ||
"--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", | ||
"--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", | ||
"--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", | ||
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", | ||
"--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", | ||
"--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", | ||
// Accessed by Lombok tests | ||
"--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", | ||
] | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
...nit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (c) 2022 Uber Technologies, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
import com.google.errorprone.CompilationTestHelper; | ||
import com.uber.nullaway.NullAway; | ||
import java.util.Arrays; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
public class NullAwayGuavaParametricNullnessTests { | ||
@Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
|
||
private CompilationTestHelper defaultCompilationHelper; | ||
|
||
@Before | ||
public void setup() { | ||
defaultCompilationHelper = | ||
CompilationTestHelper.newInstance(NullAway.class, getClass()) | ||
.setArgs( | ||
Arrays.asList( | ||
"-d", | ||
temporaryFolder.getRoot().getAbsolutePath(), | ||
"-XepOpt:NullAway:AnnotatedPackages=com.uber,com.google.common")); | ||
} | ||
|
||
@Test | ||
public void testFutureCallbackParametricNullness() { | ||
defaultCompilationHelper | ||
.addSourceLines( | ||
"Test.java", | ||
"package com.uber;", | ||
"import com.google.common.util.concurrent.FutureCallback;", | ||
"import javax.annotation.Nullable;", | ||
"class Test {", | ||
" public static <T> FutureCallback<T> wrapFutureCallback(FutureCallback<T> futureCallback) {", | ||
" return new FutureCallback<T>() {", | ||
" @Override", | ||
" public void onSuccess(@Nullable T result) {", | ||
" futureCallback.onSuccess(result);", | ||
" }", | ||
" @Override", | ||
" public void onFailure(Throwable throwable) {", | ||
" futureCallback.onFailure(throwable);", | ||
" }", | ||
" };", | ||
" }", | ||
"}") | ||
.doTest(); | ||
} | ||
|
||
@Test | ||
public void testIterableParametricNullness() { | ||
defaultCompilationHelper | ||
.addSourceLines( | ||
"Test.java", | ||
"package com.uber;", | ||
"import com.google.common.collect.ImmutableList;", | ||
"import com.google.common.collect.Iterables;", | ||
"import javax.annotation.Nullable;", | ||
"class Test {", | ||
" public static String test1() {", | ||
" // BUG: Diagnostic contains: returning @Nullable expression", | ||
" return Iterables.getFirst(ImmutableList.<String>of(), null);", | ||
" }", | ||
" public static @Nullable String test2() {", | ||
" return Iterables.getFirst(ImmutableList.<String>of(), null);", | ||
" }", | ||
"}") | ||
.doTest(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If we want coverage from tests in this module to be included as part of the overall code coverage report (sent to Coveralls), we should add an
implementation
dependence on this module here:NullAway/code-coverage-report/build.gradle
Lines 90 to 95 in 4cbd781
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.
Done. Also making sure this builds on all JDKs we support.