diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 14a8478b18..486da4d1fc 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -25,13 +25,13 @@ jobs: epVersion: 2.31.0 - os: macos-latest java: 17 - epVersion: 2.33.0 + epVersion: 2.35.1 - os: windows-latest java: 17 - epVersion: 2.33.0 + epVersion: 2.35.1 - os: ubuntu-latest java: 17 - epVersion: 2.33.0 + epVersion: 2.35.1 fail-fast: false runs-on: ${{ matrix.os }} steps: @@ -60,7 +60,7 @@ jobs: ORG_GRADLE_PROJECT_epApiVersion: ${{ matrix.epVersion }} run: ./gradlew codeCoverageReport continue-on-error: true - if: runner.os == 'Linux' && matrix.java == '17' && matrix.epVersion == '2.33.0' && github.repository == 'uber/NullAway' + if: runner.os == 'Linux' && matrix.java == '17' && matrix.epVersion == '2.35.1' && github.repository == 'uber/NullAway' - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v4 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index af6879b0d3..d1fd99c2a8 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ Changelog ========= +Version 0.12.1 +--------------- +* Add library model for Apache Commons CollectionUtils.isNotEmpty (#932) (#1062) +* Handle records in targetTypeMatches (#1061) + Version 0.12.0 --------------- IMPORTANT: diff --git a/build.gradle b/build.gradle index 812063c47a..915c01b913 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ buildscript { } plugins { id "com.diffplug.spotless" version "6.25.0" - id "net.ltgt.errorprone" version "3.1.0" apply false + id "net.ltgt.errorprone" version "4.1.0" apply false id "com.github.johnrengelman.shadow" version "8.1.1" apply false id "me.champeau.jmh" version "0.7.1" apply false id "com.github.ben-manes.versions" version "0.51.0" diff --git a/gradle.properties b/gradle.properties index 74f0dfe0c5..fa5e0e1aab 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ org.gradle.caching=true org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m GROUP=com.uber.nullaway -VERSION_NAME=0.12.1-SNAPSHOT +VERSION_NAME=0.12.2-SNAPSHOT POM_DESCRIPTION=A fast annotation-based null checker for Java diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 17b57a98bb..b74e030fda 100755 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -19,7 +19,7 @@ import org.gradle.util.VersionNumber // The oldest version of Error Prone that we support running on def oldestErrorProneVersion = "2.14.0" // Latest released Error Prone version that we've tested with -def latestErrorProneVersion = "2.33.0" +def latestErrorProneVersion = "2.35.1" // Default to using latest tested Error Prone version def defaultErrorProneVersion = latestErrorProneVersion def errorProneVersionToCompileAgainst = defaultErrorProneVersion diff --git a/jdk-recent-unit-tests/src/test/java/com/uber/nullaway/jdk17/RecordTests.java b/jdk-recent-unit-tests/src/test/java/com/uber/nullaway/jdk17/RecordTests.java index 4e83490177..7d682d6437 100644 --- a/jdk-recent-unit-tests/src/test/java/com/uber/nullaway/jdk17/RecordTests.java +++ b/jdk-recent-unit-tests/src/test/java/com/uber/nullaway/jdk17/RecordTests.java @@ -252,4 +252,27 @@ public void recordDeconstructionPatternSwitchCase() { "}") .doTest(); } + + @Test + public void issue1059() { + defaultCompilationHelper + .addSourceLines( + "BarEntity.java", + "package com.uber;", + "import org.jspecify.annotations.NonNull;", + "import org.jspecify.annotations.Nullable;", + "public class BarEntity {", + " public interface Identifiable {", + " @Nullable", + " ID id();", + " }", + " public static class Id {}", + " public record NameChanged(BarEntity.Id id, Class type) implements Identifiable<@NonNull Id> {", + " public NameChanged(BarEntity.Id id) {", + " this(id, BarEntity.class);", + " }", + " }", + "}") + .doTest(); + } } diff --git a/nullaway/build.gradle b/nullaway/build.gradle index 3f9926e4b6..c4206539ee 100644 --- a/nullaway/build.gradle +++ b/nullaway/build.gradle @@ -23,6 +23,12 @@ plugins { configurations { // A configuration holding the jars for the oldest supported version of Error Prone, to use with tests errorProneOldest + + // To resolve the errorprone dependencies for the buildWithNullAway task + errorproneExtended { + extendsFrom errorprone + canBeResolved = true + } } dependencies { @@ -152,7 +158,7 @@ tasks.register('buildWithNullAway', JavaCompile) { classpath = sourceSets.main.compileClasspath destinationDirectory = file("$buildDir/ignoredClasses") options.annotationProcessorPath = files( - configurations.errorprone.asCollection(), + configurations.errorproneExtended.asCollection(), sourceSets.main.annotationProcessorPath, // This refers to the NullAway jar built from the current source jar.archiveFile.get(), diff --git a/nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java b/nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java index eee5eb88b5..fc93add428 100644 --- a/nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java +++ b/nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java @@ -370,7 +370,13 @@ private static boolean targetTypeMatches(Symbol sym, TypeAnnotationPosition posi // on other types in the signature (e.g. `class Foo extends Bar<@A Baz> {}`). return false; default: - throw new AssertionError("unsupported element kind " + sym.getKind() + " symbol " + sym); + // Compare with toString() to preserve compatibility with JDK 11 + if (sym.getKind().toString().equals("RECORD")) { + // Records are treated like classes + return false; + } else { + throw new AssertionError("unsupported element kind " + sym.getKind() + " symbol " + sym); + } } } diff --git a/nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java b/nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java index 49aee7889b..bc1e49f703 100644 --- a/nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java +++ b/nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java @@ -741,6 +741,16 @@ private static class DefaultLibraryModels implements LibraryModels { .put(methodRef("spark.utils.StringUtils", "isNotBlank(java.lang.CharSequence)"), 0) .put(methodRef("spark.utils.StringUtils", "hasLength(java.lang.String)"), 0) .put(methodRef("spark.utils.StringUtils", "hasLength(java.lang.CharSequence)"), 0) + .put( + methodRef( + "org.apache.commons.collections.CollectionUtils", + "isNotEmpty(java.util.Collection)"), + 0) + .put( + methodRef( + "org.apache.commons.collections4.CollectionUtils", + "isNotEmpty(java.util.Collection)"), + 0) .put( methodRef("org.apache.commons.lang.StringUtils", "isNotEmpty(java.lang.String)"), 0) .put( diff --git a/nullaway/src/test/java/com/uber/nullaway/AndroidTest.java b/nullaway/src/test/java/com/uber/nullaway/AndroidTest.java index c00de7f993..724879c987 100644 --- a/nullaway/src/test/java/com/uber/nullaway/AndroidTest.java +++ b/nullaway/src/test/java/com/uber/nullaway/AndroidTest.java @@ -33,8 +33,8 @@ public void setup() { public void coreFragmentSuccess() { initialiseAndroidCoreClasses(); compilationHelper - .addSourceFile("androidstubs/core/Fragment.java") - .addSourceFile("android-success/CoreFragment.java") + .addSourceFile("testdata/androidstubs/core/Fragment.java") + .addSourceFile("testdata/android-success/CoreFragment.java") .doTest(); } @@ -42,8 +42,8 @@ public void coreFragmentSuccess() { public void coreFragmentMissingOnAttachError() { initialiseAndroidCoreClasses(); compilationHelper - .addSourceFile("androidstubs/core/Fragment.java") - .addSourceFile("android-error/CoreFragmentWithoutOnAttach.java") + .addSourceFile("testdata/androidstubs/core/Fragment.java") + .addSourceFile("testdata/android-error/CoreFragmentWithoutOnAttach.java") .doTest(); } @@ -51,8 +51,8 @@ public void coreFragmentMissingOnAttachError() { public void coreFragmentMissingOnCreateError() { initialiseAndroidCoreClasses(); compilationHelper - .addSourceFile("androidstubs/core/Fragment.java") - .addSourceFile("android-error/CoreFragmentWithoutOnCreate.java") + .addSourceFile("testdata/androidstubs/core/Fragment.java") + .addSourceFile("testdata/android-error/CoreFragmentWithoutOnCreate.java") .doTest(); } @@ -60,8 +60,8 @@ public void coreFragmentMissingOnCreateError() { public void coreFragmentMissingOnCreateViewError() { initialiseAndroidCoreClasses(); compilationHelper - .addSourceFile("androidstubs/core/Fragment.java") - .addSourceFile("android-error/CoreFragmentWithoutOnCreateView.java") + .addSourceFile("testdata/androidstubs/core/Fragment.java") + .addSourceFile("testdata/android-error/CoreFragmentWithoutOnCreateView.java") .doTest(); } @@ -70,8 +70,8 @@ public void coreFragmentMissingOnCreateViewError() { public void androidxFragmentSuccess() { initialiseAndroidCoreClasses(); compilationHelper - .addSourceFile("androidstubs/androidx/Fragment.java") - .addSourceFile("android-success/AndroidxFragment.java") + .addSourceFile("testdata/androidstubs/androidx/Fragment.java") + .addSourceFile("testdata/android-success/AndroidxFragment.java") .doTest(); } @@ -79,8 +79,8 @@ public void androidxFragmentSuccess() { public void androidxFragmentMissingOnAttachError() { initialiseAndroidCoreClasses(); compilationHelper - .addSourceFile("androidstubs/androidx/Fragment.java") - .addSourceFile("android-error/AndroidxFragmentWithoutOnAttach.java") + .addSourceFile("testdata/androidstubs/androidx/Fragment.java") + .addSourceFile("testdata/android-error/AndroidxFragmentWithoutOnAttach.java") .doTest(); } @@ -88,8 +88,8 @@ public void androidxFragmentMissingOnAttachError() { public void androidxFragmentMissingOnCreateError() { initialiseAndroidCoreClasses(); compilationHelper - .addSourceFile("androidstubs/androidx/Fragment.java") - .addSourceFile("android-error/AndroidxFragmentWithoutOnCreate.java") + .addSourceFile("testdata/androidstubs/androidx/Fragment.java") + .addSourceFile("testdata/android-error/AndroidxFragmentWithoutOnCreate.java") .doTest(); } @@ -97,8 +97,8 @@ public void androidxFragmentMissingOnCreateError() { public void androidxFragmentMissingOnCreateViewError() { initialiseAndroidCoreClasses(); compilationHelper - .addSourceFile("androidstubs/androidx/Fragment.java") - .addSourceFile("android-error/AndroidxFragmentWithoutOnCreateView.java") + .addSourceFile("testdata/androidstubs/androidx/Fragment.java") + .addSourceFile("testdata/android-error/AndroidxFragmentWithoutOnCreateView.java") .doTest(); } @@ -108,8 +108,8 @@ public void androidxFragmentMissingOnCreateViewError() { public void supportLibFragmentSuccess() { initialiseAndroidCoreClasses(); compilationHelper - .addSourceFile("androidstubs/supportlib/Fragment.java") - .addSourceFile("android-success/SupportLibraryFragment.java") + .addSourceFile("testdata/androidstubs/supportlib/Fragment.java") + .addSourceFile("testdata/android-success/SupportLibraryFragment.java") .doTest(); } @@ -117,8 +117,8 @@ public void supportLibFragmentSuccess() { public void supportLibFragmentMissingOnAttachError() { initialiseAndroidCoreClasses(); compilationHelper - .addSourceFile("androidstubs/supportlib/Fragment.java") - .addSourceFile("android-error/SupportLibraryFragmentWithoutOnAttach.java") + .addSourceFile("testdata/androidstubs/supportlib/Fragment.java") + .addSourceFile("testdata/android-error/SupportLibraryFragmentWithoutOnAttach.java") .doTest(); } @@ -126,8 +126,8 @@ public void supportLibFragmentMissingOnAttachError() { public void supportLibFragmentMissingOnCreateError() { initialiseAndroidCoreClasses(); compilationHelper - .addSourceFile("androidstubs/supportlib/Fragment.java") - .addSourceFile("android-error/SupportLibraryFragmentWithoutOnCreate.java") + .addSourceFile("testdata/androidstubs/supportlib/Fragment.java") + .addSourceFile("testdata/android-error/SupportLibraryFragmentWithoutOnCreate.java") .doTest(); } @@ -135,8 +135,8 @@ public void supportLibFragmentMissingOnCreateError() { public void supportLibFragmentMissingOnCreateViewError() { initialiseAndroidCoreClasses(); compilationHelper - .addSourceFile("androidstubs/supportlib/Fragment.java") - .addSourceFile("android-error/SupportLibraryFragmentWithoutOnCreateView.java") + .addSourceFile("testdata/androidstubs/supportlib/Fragment.java") + .addSourceFile("testdata/android-error/SupportLibraryFragmentWithoutOnCreateView.java") .doTest(); } @@ -146,8 +146,8 @@ public void supportLibFragmentMissingOnCreateViewError() { public void coreActivitySuccess() { initialiseAndroidCoreClasses(); compilationHelper - .addSourceFile("androidstubs/core/Activity.java") - .addSourceFile("android-success/CoreActivity.java") + .addSourceFile("testdata/androidstubs/core/Activity.java") + .addSourceFile("testdata/android-success/CoreActivity.java") .doTest(); } @@ -157,8 +157,8 @@ public void coreActivitySuccess() { public void supportLibActivitySuccess() { initialiseAndroidCoreClasses(); compilationHelper - .addSourceFile("androidstubs/supportlib/ActivityCompat.java") - .addSourceFile("android-success/SupportLibActivityCompat.java") + .addSourceFile("testdata/androidstubs/supportlib/ActivityCompat.java") + .addSourceFile("testdata/android-success/SupportLibActivityCompat.java") .doTest(); } @@ -168,8 +168,8 @@ public void supportLibActivitySuccess() { public void androidxActivitySuccess() { initialiseAndroidCoreClasses(); compilationHelper - .addSourceFile("androidstubs/androidx/ActivityCompat.java") - .addSourceFile("android-success/AndroidxActivityCompat.java") + .addSourceFile("testdata/androidstubs/androidx/ActivityCompat.java") + .addSourceFile("testdata/android-success/AndroidxActivityCompat.java") .doTest(); } @@ -177,11 +177,11 @@ public void androidxActivitySuccess() { @SuppressWarnings("CheckReturnValue") private void initialiseAndroidCoreClasses() { compilationHelper - .addSourceFile("androidstubs/core/Context.java") - .addSourceFile("androidstubs/core/Bundle.java") - .addSourceFile("androidstubs/core/LayoutInflater.java") - .addSourceFile("androidstubs/core/PersistableBundle.java") - .addSourceFile("androidstubs/core/View.java") - .addSourceFile("androidstubs/core/ViewGroup.java"); + .addSourceFile("testdata/androidstubs/core/Context.java") + .addSourceFile("testdata/androidstubs/core/Bundle.java") + .addSourceFile("testdata/androidstubs/core/LayoutInflater.java") + .addSourceFile("testdata/androidstubs/core/PersistableBundle.java") + .addSourceFile("testdata/androidstubs/core/View.java") + .addSourceFile("testdata/androidstubs/core/ViewGroup.java"); } } diff --git a/nullaway/src/test/java/com/uber/nullaway/ContractsTests.java b/nullaway/src/test/java/com/uber/nullaway/ContractsTests.java index 664dffaab8..4e68a3dcb9 100644 --- a/nullaway/src/test/java/com/uber/nullaway/ContractsTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/ContractsTests.java @@ -13,7 +13,7 @@ public void checkContractPositiveCases() { temporaryFolder.getRoot().getAbsolutePath(), "-XepOpt:NullAway:AnnotatedPackages=com.uber", "-XepOpt:NullAway:CheckContracts=true")) - .addSourceFile("CheckContractPositiveCases.java") + .addSourceFile("testdata/CheckContractPositiveCases.java") .doTest(); } @@ -25,7 +25,7 @@ public void checkContractNegativeCases() { temporaryFolder.getRoot().getAbsolutePath(), "-XepOpt:NullAway:AnnotatedPackages=com.uber", "-XepOpt:NullAway:CheckContracts=true")) - .addSourceFile("CheckContractNegativeCases.java") + .addSourceFile("testdata/CheckContractNegativeCases.java") .doTest(); } diff --git a/nullaway/src/test/java/com/uber/nullaway/CoreTests.java b/nullaway/src/test/java/com/uber/nullaway/CoreTests.java index a851d8efb2..17cc70455c 100644 --- a/nullaway/src/test/java/com/uber/nullaway/CoreTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/CoreTests.java @@ -33,27 +33,29 @@ public class CoreTests extends NullAwayTestsBase { @Test public void coreNullabilityPositiveCases() { - defaultCompilationHelper.addSourceFile("NullAwayPositiveCases.java").doTest(); + defaultCompilationHelper.addSourceFile("testdata/NullAwayPositiveCases.java").doTest(); } @Test public void nullabilityAnonymousClass() { - defaultCompilationHelper.addSourceFile("NullAwayAnonymousClass.java").doTest(); + defaultCompilationHelper.addSourceFile("testdata/NullAwayAnonymousClass.java").doTest(); } @Test public void coreNullabilityNegativeCases() { defaultCompilationHelper - .addSourceFile("NullAwayNegativeCases.java") - .addSourceFile("OtherStuff.java") - .addSourceFile("TestAnnot.java") - .addSourceFile("unannotated/UnannotatedClass.java") + .addSourceFile("testdata/NullAwayNegativeCases.java") + .addSourceFile("testdata/OtherStuff.java") + .addSourceFile("testdata/TestAnnot.java") + .addSourceFile("testdata/unannotated/UnannotatedClass.java") .doTest(); } @Test public void assertSupportPositiveCases() { - defaultCompilationHelper.addSourceFile("CheckAssertSupportPositiveCases.java").doTest(); + defaultCompilationHelper + .addSourceFile("testdata/CheckAssertSupportPositiveCases.java") + .doTest(); } @Test @@ -64,7 +66,7 @@ public void assertSupportNegativeCases() { temporaryFolder.getRoot().getAbsolutePath(), "-XepOpt:NullAway:AnnotatedPackages=com.uber", "-XepOpt:NullAway:AssertsEnabled=true")) - .addSourceFile("CheckAssertSupportNegativeCases.java") + .addSourceFile("testdata/CheckAssertSupportNegativeCases.java") .doTest(); } @@ -258,7 +260,7 @@ public void supportSwitchExpression() { @Test public void testCastToNonNull() { defaultCompilationHelper - .addSourceFile("Util.java") + .addSourceFile("testdata/Util.java") .addSourceLines( "Test.java", "package com.uber;", @@ -279,7 +281,7 @@ public void testCastToNonNull() { @Test public void testCastToNonNullExtraArgsWarning() { defaultCompilationHelper - .addSourceFile("Util.java") + .addSourceFile("testdata/Util.java") .addSourceLines( "Test.java", "package com.uber;", @@ -384,7 +386,7 @@ public void invokeNativeFromInitializer() { @Test public void testCapturingScopes() { - defaultCompilationHelper.addSourceFile("CapturingScopes.java").doTest(); + defaultCompilationHelper.addSourceFile("testdata/CapturingScopes.java").doTest(); } @Test @@ -635,7 +637,7 @@ public void testMapWithMapGetKey() { @Test public void tryFinallySupport() { - defaultCompilationHelper.addSourceFile("NullAwayTryFinallyCases.java").doTest(); + defaultCompilationHelper.addSourceFile("testdata/NullAwayTryFinallyCases.java").doTest(); } @Test diff --git a/nullaway/src/test/java/com/uber/nullaway/FrameworkTests.java b/nullaway/src/test/java/com/uber/nullaway/FrameworkTests.java index b4e34a2533..e364edc989 100644 --- a/nullaway/src/test/java/com/uber/nullaway/FrameworkTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/FrameworkTests.java @@ -6,36 +6,40 @@ public class FrameworkTests extends NullAwayTestsBase { @Test public void lombokSupportTesting() { - defaultCompilationHelper.addSourceFile("lombok/LombokBuilderInit.java").doTest(); + defaultCompilationHelper.addSourceFile("testdata/lombok/LombokBuilderInit.java").doTest(); } @Test public void coreNullabilityNativeModels() { defaultCompilationHelper - .addSourceFile("NullAwayNativeModels.java") - .addSourceFile("androidstubs/WebView.java") - .addSourceFile("androidstubs/TextUtils.java") + .addSourceFile("testdata/NullAwayNativeModels.java") + .addSourceFile("testdata/androidstubs/WebView.java") + .addSourceFile("testdata/androidstubs/TextUtils.java") .doTest(); } @Test public void rxSupportPositiveCases() { - defaultCompilationHelper.addSourceFile("NullAwayRxSupportPositiveCases.java").doTest(); + defaultCompilationHelper.addSourceFile("testdata/NullAwayRxSupportPositiveCases.java").doTest(); } @Test public void rxSupportNegativeCases() { - defaultCompilationHelper.addSourceFile("NullAwayRxSupportNegativeCases.java").doTest(); + defaultCompilationHelper.addSourceFile("testdata/NullAwayRxSupportNegativeCases.java").doTest(); } @Test public void streamSupportNegativeCases() { - defaultCompilationHelper.addSourceFile("NullAwayStreamSupportNegativeCases.java").doTest(); + defaultCompilationHelper + .addSourceFile("testdata/NullAwayStreamSupportNegativeCases.java") + .doTest(); } @Test public void streamSupportPositiveCases() { - defaultCompilationHelper.addSourceFile("NullAwayStreamSupportPositiveCases.java").doTest(); + defaultCompilationHelper + .addSourceFile("testdata/NullAwayStreamSupportPositiveCases.java") + .doTest(); } @Test @@ -382,8 +386,8 @@ public void springAutowiredFieldTest() { @Test public void springTestAutowiredFieldTest() { defaultCompilationHelper - .addSourceFile("springboot-annotations/MockBean.java") - .addSourceFile("springboot-annotations/SpyBean.java") + .addSourceFile("testdata/springboot-annotations/MockBean.java") + .addSourceFile("testdata/springboot-annotations/SpyBean.java") .addSourceLines( "Foo.java", "package com.uber;", @@ -1017,6 +1021,42 @@ public void apacheValidateStringValidIndex() { .doTest(); } + @Test + public void apacheCollectionsCollectionUtilsIsNotEmpty() { + defaultCompilationHelper + .addSourceLines( + "Foo.java", + "package com.uber;", + "import org.apache.commons.collections.CollectionUtils;", + "import org.jetbrains.annotations.Nullable;", + "import java.util.List;", + "public class Foo {", + " public void bar(@Nullable List s) {", + " if(CollectionUtils.isNotEmpty(s))", + " s.get(0);", + " }", + "}") + .doTest(); + } + + @Test + public void apacheCollections4CollectionUtilsIsNotEmpty() { + defaultCompilationHelper + .addSourceLines( + "Foo.java", + "package com.uber;", + "import org.apache.commons.collections4.CollectionUtils;", + "import org.jetbrains.annotations.Nullable;", + "import java.util.List;", + "public class Foo {", + " public void bar(@Nullable List s) {", + " if(CollectionUtils.isNotEmpty(s))", + " s.get(0);", + " }", + "}") + .doTest(); + } + @Test public void filesIsDirectory() { defaultCompilationHelper diff --git a/nullaway/src/test/java/com/uber/nullaway/InitializationTests.java b/nullaway/src/test/java/com/uber/nullaway/InitializationTests.java index 2bd7af9f0e..75e56db1e9 100644 --- a/nullaway/src/test/java/com/uber/nullaway/InitializationTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/InitializationTests.java @@ -6,27 +6,27 @@ public class InitializationTests extends NullAwayTestsBase { @Test public void initFieldPositiveCases() { - defaultCompilationHelper.addSourceFile("CheckFieldInitPositiveCases.java").doTest(); + defaultCompilationHelper.addSourceFile("testdata/CheckFieldInitPositiveCases.java").doTest(); } @Test public void initFieldNegativeCases() { - defaultCompilationHelper.addSourceFile("CheckFieldInitNegativeCases.java").doTest(); + defaultCompilationHelper.addSourceFile("testdata/CheckFieldInitNegativeCases.java").doTest(); } @Test public void readBeforeInitPositiveCases() { defaultCompilationHelper - .addSourceFile("ReadBeforeInitPositiveCases.java") - .addSourceFile("Util.java") + .addSourceFile("testdata/ReadBeforeInitPositiveCases.java") + .addSourceFile("testdata/Util.java") .doTest(); } @Test public void readBeforeInitNegativeCases() { defaultCompilationHelper - .addSourceFile("ReadBeforeInitNegativeCases.java") - .addSourceFile("Util.java") + .addSourceFile("testdata/ReadBeforeInitNegativeCases.java") + .addSourceFile("testdata/Util.java") .doTest(); } diff --git a/nullaway/src/test/java/com/uber/nullaway/Java8Tests.java b/nullaway/src/test/java/com/uber/nullaway/Java8Tests.java index 8541c445af..bc77c97c43 100644 --- a/nullaway/src/test/java/com/uber/nullaway/Java8Tests.java +++ b/nullaway/src/test/java/com/uber/nullaway/Java8Tests.java @@ -5,22 +5,26 @@ public class Java8Tests extends NullAwayTestsBase { @Test public void java8PositiveCases() { - defaultCompilationHelper.addSourceFile("NullAwayJava8PositiveCases.java").doTest(); + defaultCompilationHelper.addSourceFile("testdata/NullAwayJava8PositiveCases.java").doTest(); } @Test public void java8NegativeCases() { - defaultCompilationHelper.addSourceFile("NullAwayJava8NegativeCases.java").doTest(); + defaultCompilationHelper.addSourceFile("testdata/NullAwayJava8NegativeCases.java").doTest(); } @Test public void functionalMethodSuperInterface() { - defaultCompilationHelper.addSourceFile("NullAwaySuperFunctionalInterface.java").doTest(); + defaultCompilationHelper + .addSourceFile("testdata/NullAwaySuperFunctionalInterface.java") + .doTest(); } @Test public void functionalMethodOverrideSuperInterface() { - defaultCompilationHelper.addSourceFile("NullAwayOverrideFunctionalInterfaces.java").doTest(); + defaultCompilationHelper + .addSourceFile("testdata/NullAwayOverrideFunctionalInterfaces.java") + .doTest(); } @Test diff --git a/nullaway/src/test/java/com/uber/nullaway/ThriftTests.java b/nullaway/src/test/java/com/uber/nullaway/ThriftTests.java index a3180f2fe6..aa5b67ebe1 100644 --- a/nullaway/src/test/java/com/uber/nullaway/ThriftTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/ThriftTests.java @@ -156,7 +156,7 @@ public void testThriftAndCastToNonNull() { "-XepOpt:NullAway:CastToNonNullMethod=com.uber.nullaway.testdata.Util.castToNonNull", "-XepOpt:NullAway:TreatGeneratedAsUnannotated=true", "-XepOpt:NullAway:AcknowledgeRestrictiveAnnotations=true")) - .addSourceFile("Util.java") + .addSourceFile("testdata/Util.java") .addSourceLines("TBase.java", "package org.apache.thrift;", "public interface TBase {}") .addSourceLines( "GeneratedClass.java", diff --git a/nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java b/nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java index 992cbff0d0..41a8179a90 100644 --- a/nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/UnannotatedTests.java @@ -8,10 +8,10 @@ public class UnannotatedTests extends NullAwayTestsBase { @Test public void coreNullabilitySkipClass() { defaultCompilationHelper - .addSourceFile("Shape_Stuff.java") - .addSourceFile("excluded/Shape_Stuff2.java") - .addSourceFile("AnnotatedClass.java") - .addSourceFile("TestAnnot.java") + .addSourceFile("testdata/Shape_Stuff.java") + .addSourceFile("testdata/excluded/Shape_Stuff2.java") + .addSourceFile("testdata/AnnotatedClass.java") + .addSourceFile("testdata/TestAnnot.java") .doTest(); } @@ -68,7 +68,7 @@ public void skipNestedClass() { @Test public void coreNullabilitySkipPackage() { - defaultCompilationHelper.addSourceFile("unannotated/UnannotatedClass.java").doTest(); + defaultCompilationHelper.addSourceFile("testdata/unannotated/UnannotatedClass.java").doTest(); } @Test