-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consider nullable annotations in explicit nulls
Fixes #21629
- Loading branch information
Showing
5 changed files
with
96 additions
and
6 deletions.
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
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,50 @@ | ||
package javax.annotation; | ||
import java.util.*; | ||
|
||
public class J { | ||
|
||
private static String getK() { | ||
return "k"; | ||
} | ||
|
||
@Nullable | ||
public static final String k = getK(); | ||
|
||
@Nullable | ||
public static String l = "l"; | ||
|
||
@Nullable | ||
public final String m = null; | ||
|
||
@Nullable | ||
public String n = "n"; | ||
|
||
@Nullable | ||
public static final String f(int i) { | ||
return "f: " + i; | ||
} | ||
|
||
@Nullable | ||
public static String g(int i) { | ||
return "g: " + i; | ||
} | ||
|
||
@Nullable | ||
public String h(int i) { | ||
return "h: " + i; | ||
} | ||
|
||
@Nullable | ||
public <T> String[] genericf(T a) { | ||
String[] as = new String[1]; | ||
as[0] = "" + a; | ||
return as; | ||
} | ||
|
||
@Nullable | ||
public <T> List<T> genericg(T a) { | ||
List<T> as = new ArrayList<T>(); | ||
as.add(a); | ||
return as; | ||
} | ||
} |
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,8 @@ | ||
package javax.annotation; | ||
|
||
import java.lang.annotation.*; | ||
|
||
// A "fake" Nullable Annotation for jsr305 | ||
@Retention(value = RetentionPolicy.RUNTIME) | ||
@interface Nullable { | ||
} |
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,15 @@ | ||
// Test that Nullable annotations are working in Java files. | ||
|
||
import javax.annotation.J | ||
|
||
class S_3 { | ||
def kk: String = J.k // error | ||
def ll: String = J.l // error | ||
def mm: String = (new J).m // error | ||
def nn: String = (new J).n // error | ||
def ff(i: Int): String = J.f(i) // error | ||
def gg(i: Int): String = J.g(i) // error | ||
def hh(i: Int): String = (new J).h(i) // error | ||
def genericff(a: String | Null): Array[String | Null] = (new J).genericf(a) // error | ||
def genericgg(a: String | Null): java.util.List[String] = (new J).genericg(a) // error | ||
} |