Summary: This diff does it for inheritance violation issues. Reviewed By: artempyanykh Differential Revision: D19393748 fbshipit-source-id: 47be41e77master
parent
9199aa4b24
commit
6417b19ace
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* 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) {}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue