You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.5 KiB
89 lines
2.5 KiB
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
/** Test for checking how @NullsafeStrict mode plays with inheritance rule */
|
|
package codetoanalyze.java.nullsafe_default;
|
|
|
|
import com.facebook.infer.annotation.NullsafeStrict;
|
|
import javax.annotation.Nullable;
|
|
|
|
public class InheritanceForStrictMode {
|
|
class NonStrictBase {
|
|
public @Nullable String okToRemoveNullableInChildren() {
|
|
return null;
|
|
}
|
|
|
|
public String badToAddNullableInChildren() {
|
|
return "";
|
|
}
|
|
|
|
public void params(
|
|
@Nullable String badToRemoveNullableInChildren, String okToAddNullableInChildren) {}
|
|
}
|
|
|
|
// Exactly as NonStrictBase, except that it is marked as @NullsafeStrict
|
|
@NullsafeStrict
|
|
class StrictBase {
|
|
public @Nullable String okToRemoveNullableInChildren() {
|
|
return null;
|
|
}
|
|
|
|
public String badToAddNullableInChildren() {
|
|
return "";
|
|
}
|
|
|
|
public void params(
|
|
@Nullable String badToRemoveNullableInChildren, String okToAddNullableInChildren) {}
|
|
}
|
|
|
|
// Expecting all issues to be surfaced as ERRORs
|
|
// NOTE: we currently DON'T require the base to be strictified in order to strictify a child (see
|
|
// T60513926)
|
|
@NullsafeStrict
|
|
class StrictExtendingNonstrict extends NonStrictBase {
|
|
public @Override String okToRemoveNullableInChildren() {
|
|
return "";
|
|
}
|
|
|
|
public @Override @Nullable String badToAddNullableInChildren() {
|
|
return null;
|
|
}
|
|
|
|
public @Override void params(
|
|
String badToRemoveNullableInChildren, @Nullable String okToAddNullableInChildren) {}
|
|
}
|
|
|
|
// Expecting all issues to be surfaced as ERRORs
|
|
@NullsafeStrict
|
|
class StrictExtendingStrict extends StrictBase {
|
|
public @Override String okToRemoveNullableInChildren() {
|
|
return "";
|
|
}
|
|
|
|
public @Override @Nullable String badToAddNullableInChildren() {
|
|
return null;
|
|
}
|
|
|
|
public @Override void params(
|
|
String badToRemoveNullableInChildren, @Nullable String okToAddNullableInChildren) {}
|
|
}
|
|
|
|
// Expecting all issues to be surfaces as WARNINGs (even that we extend a strict class)
|
|
class NonStrictExtendingStrict extends StrictBase {
|
|
public @Override String okToRemoveNullableInChildren() {
|
|
return "";
|
|
}
|
|
|
|
public @Override @Nullable String badToAddNullableInChildren() {
|
|
return null;
|
|
}
|
|
|
|
public @Override void params(
|
|
String badToRemoveNullableInChildren, @Nullable String okToAddNullableInChildren) {}
|
|
}
|
|
}
|