Skip to content

Commit

Permalink
Merge branch 'switch-statement-rule' into switch-expressions-jjjpv-3
Browse files Browse the repository at this point in the history
  • Loading branch information
smillst committed Dec 16, 2021
2 parents a04acc7 + c32115f commit 30dccf2
Show file tree
Hide file tree
Showing 21 changed files with 882 additions and 80 deletions.
Empty file added SKIP-REQUIRE-JAVADOC
Empty file.
12 changes: 4 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import de.undercouch.gradle.tasks.download.Download

plugins {
// https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow (v5 requires Gradle 5)
id 'com.github.johnrengelman.shadow' version '7.1.0'
id 'com.github.johnrengelman.shadow' version '7.1.1'
// https://plugins.gradle.org/plugin/de.undercouch.download
id "de.undercouch.download" version "4.1.2"
id 'java'
Expand Down Expand Up @@ -690,15 +690,11 @@ subprojects {
// * Temporarily comment out "-Werror" elsewhere in this file
// * Repeatedly run `./gradlew clean compileJava` and fix all errors
// * Uncomment "-Werror"
// * Don't edit framework/build.gradle to use the same version number
// (it is updated when the annotated version of Guava is updated).
errorprone group: 'com.google.errorprone', name: 'error_prone_core', version: '2.10.0'
ext.errorproneVersion = '2.10.0'
errorprone group: 'com.google.errorprone', name: 'error_prone_core', version: errorproneVersion

// TODO: it's a bug that annotatedlib:guava requires the error_prone_annotations dependency.
// Update the next two version numbers in tandem. Get the Error Prone version from the "compile
// dependencies" section of https://mvnrepository.com/artifact/com.google.guava/guava/30.1.1-jre .
// (It isn't at https://mvnrepository.com/artifact/org.checkerframework.annotatedlib/guava/30.1.1-jre, which is the bug.)
annotatedGuava 'com.google.errorprone:error_prone_annotations:2.5.1'
annotatedGuava "com.google.errorprone:error_prone_annotations:${errorproneVersion}"
annotatedGuava ('org.checkerframework.annotatedlib:guava:30.1.1-jre') {
// So long as Guava only uses annotations from checker-qual, excluding it should not cause problems.
exclude group: 'org.checkerframework'
Expand Down
2 changes: 0 additions & 2 deletions checker/tests/nullness/java17/NullnessSwitchArrows.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ void method2() {
default -> throw new IllegalStateException("Invalid day: " + day);
}

// TODO: this is a false positive. It works for case: statements; see below.
// :: error: (dereference.of.nullable)
o.toString();
}

Expand Down
4 changes: 0 additions & 4 deletions checker/tests/nullness/java17/NullnessSwitchExpressions.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ void method2() {
default -> throw new IllegalStateException("Invalid day: " + day);
};

// TODO: This is a false positive.
// :: error: (dereference.of.nullable)
o.toString();
}

Expand All @@ -51,8 +49,6 @@ void method3() {
String s = null;
if (day == Day.THURSDAY) {
s = "hello";
// TODO: This is a false positive.
// :: error: (dereference.of.nullable)
s.toString();
}
yield s;
Expand Down
43 changes: 43 additions & 0 deletions checker/tests/nullness/java17/NullnessSwitchStatementRules.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// @below-java17-jdk-skip-test
import org.checkerframework.checker.nullness.qual.Nullable;

public class NullnessSwitchStatementRules {
@Nullable Object field = null;

void method(int selector) {
field = new Object();
switch (selector) {
case 1 -> field = null;
case 2 -> field.toString();
}

field = new Object();
switch (selector) {
case 1 -> {
field = null;
}
case 2 -> {
field.toString();
}
}

field = new Object();
switch (selector) {
case 1 -> {
field = null;
}
case 2 -> {
field.toString();
}
}

field = new Object();
switch (selector) {
case 1:
field = null;
case 2:
// :: error: (dereference.of.nullable)
field.toString();
}
}
}
27 changes: 27 additions & 0 deletions checker/tests/nullness/java17/SwitchExpressionInvariant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @below-java17-jdk-skip-test
import java.util.List;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

public class SwitchExpressionInvariant {
public static boolean flag = false;

void method(
List<@NonNull String> nonnullStrings, List<@Nullable String> nullableStrings, int fenum) {

List<@NonNull String> list =
// :: error: (assignment)
switch (fenum) {
// :: error: (switch.expression)
case 1 -> nonnullStrings;
default -> nullableStrings;
};

List<@Nullable String> list2 =
switch (fenum) {
// :: error: (switch.expression)
case 1 -> nonnullStrings;
default -> nullableStrings;
};
}
}
Loading

0 comments on commit 30dccf2

Please sign in to comment.