Skip to content

Commit

Permalink
Merge branch 'master' into task2
Browse files Browse the repository at this point in the history
  • Loading branch information
haewiful authored Oct 30, 2024
2 parents 8272843 + 238363a commit dab6f07
Show file tree
Hide file tree
Showing 17 changed files with 181 additions and 85 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ID> {",
" @Nullable",
" ID id();",
" }",
" public static class Id {}",
" public record NameChanged(BarEntity.Id id, Class<BarEntity> type) implements Identifiable<@NonNull Id> {",
" public NameChanged(BarEntity.Id id) {",
" this(id, BarEntity.class);",
" }",
" }",
"}")
.doTest();
}
}
8 changes: 7 additions & 1 deletion nullaway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
72 changes: 36 additions & 36 deletions nullaway/src/test/java/com/uber/nullaway/AndroidTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,35 @@ 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();
}

@Test
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();
}

@Test
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();
}

@Test
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();
}

Expand All @@ -70,35 +70,35 @@ 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();
}

@Test
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();
}

@Test
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();
}

@Test
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();
}

Expand All @@ -108,35 +108,35 @@ 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();
}

@Test
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();
}

@Test
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();
}

@Test
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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -168,20 +168,20 @@ 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();
}

/** Initialises the default android classes that are commonly used. */
@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");
}
}
4 changes: 2 additions & 2 deletions nullaway/src/test/java/com/uber/nullaway/ContractsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand Down
Loading

0 comments on commit dab6f07

Please sign in to comment.