-
Notifications
You must be signed in to change notification settings - Fork 329
Closed
Labels
bugjspecifyRelated to support for jspecify standard (see jspecify.dev)Related to support for jspecify standard (see jspecify.dev)
Description
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE_USE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER,
ElementType.LOCAL_VARIABLE })
public @interface Nullable {
}
--------------------------------------------------------------------------
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE_USE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER,
ElementType.LOCAL_VARIABLE })
public @interface NonNull {
}
--------------------------------------------------------------------------
protected static String composeName(@Nullable String @NonNull... names) {
StringJoiner stringJoiner = new StringJoiner(":");
for (String name : names) {
if (name != null && !name.isEmpty()) {
stringJoiner.add(name);
}
}
return stringJoiner.toString();
}
result:
error: [NullAway] enhanced-for expression names is @Nullable
which points to line:
for (String name : names) {
Key facts:
namesis vararg array, it's expected to be not-null and contain:- Nullable String elements
- For some reason these two annotations are mixed.
There is also one answer I found helpful:
https://stackoverflow.com/questions/32327134/where-does-a-nullable-annotation-refer-to-in-case-of-a-varargs-parameter
Metadata
Metadata
Assignees
Labels
bugjspecifyRelated to support for jspecify standard (see jspecify.dev)Related to support for jspecify standard (see jspecify.dev)