Summary: This is fragile and redundant. Reviewed By: ezgicicek Differential Revision: D20249041 fbshipit-source-id: fc22bc0fbmaster
parent
8a01b259ff
commit
fa4f9ef5f3
@ -1,9 +0,0 @@
|
||||
[buildfile]
|
||||
includes = //DEFS
|
||||
|
||||
[project]
|
||||
ignore = .git, .ml, .mli
|
||||
|
||||
[java]
|
||||
source_level = 8
|
||||
target_level = 8
|
@ -1 +0,0 @@
|
||||
../../../../.buckversion
|
@ -1,52 +0,0 @@
|
||||
import os
|
||||
|
||||
original_java_library = java_library
|
||||
def java_library(
|
||||
name,
|
||||
srcs=[],
|
||||
**kwargs
|
||||
):
|
||||
|
||||
original_java_library(
|
||||
name=name,
|
||||
srcs=srcs,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
create_infer_genrule(name, srcs)
|
||||
|
||||
original_android_library = android_library
|
||||
def android_library(
|
||||
name,
|
||||
srcs=[],
|
||||
**kwargs
|
||||
):
|
||||
|
||||
original_android_library(
|
||||
name=name,
|
||||
srcs=srcs,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
create_infer_genrule(name, srcs)
|
||||
|
||||
def create_infer_genrule(
|
||||
name,
|
||||
srcs
|
||||
):
|
||||
genrule_name = name + '_infer'
|
||||
genrule(
|
||||
name = genrule_name,
|
||||
srcs=srcs,
|
||||
cmd = ' '.join([
|
||||
os.getenv('INFER_BIN', 'infer'),
|
||||
'--genrule-mode',
|
||||
'--project-root', os.getenv('PROJECT_ROOT', os.environ['PWD']),
|
||||
'--eradicate-only',
|
||||
'--results-dir', '$OUT',
|
||||
'--classpath', '$(classpath :{})'.format(name),
|
||||
'--sourcepath', '$SRCDIR',
|
||||
'--generated-classes', '$(location :{})'.format(name),
|
||||
]),
|
||||
out = 'infer_out',
|
||||
)
|
@ -1,27 +0,0 @@
|
||||
# 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.
|
||||
|
||||
TESTS_DIR = ../..
|
||||
|
||||
BUCK_TARGET = //module2:module2
|
||||
INFER_TARGET = $(BUCK_TARGET)_infer
|
||||
INFERPRINT_OPTIONS = --issues-tests
|
||||
SOURCES = $(shell find . -name '*.java')
|
||||
CLEAN_EXTRA = buck-out
|
||||
INFER_OUT = buck-out/gen/module2/module2_infer/infer_out
|
||||
JSON_REPORT = $(INFER_OUT)/report.json
|
||||
|
||||
include $(TESTS_DIR)/java.make
|
||||
include $(TESTS_DIR)/infer.make
|
||||
|
||||
$(JSON_REPORT): $(JAVA_DEPS) $(SOURCES) $(MAKEFILE_LIST)
|
||||
$(QUIET)$(REMOVE_DIR) buck-out && \
|
||||
$(call silent_on_success,Testing Buck genrule for Java integration,\
|
||||
INFER_BIN="$(INFER_BIN)" $(BUCK) build --no-cache $(INFER_TARGET))
|
||||
$(QUIET)touch $@
|
||||
|
||||
issues.exp.test$(TEST_SUFFIX): $(JSON_REPORT) $(INFER_BIN)
|
||||
$(QUIET)$(INFER_BIN) report -q \
|
||||
$(INFERPRINT_OPTIONS) $@ --from-json-report $(JSON_REPORT)
|
@ -1,7 +0,0 @@
|
||||
java_library(
|
||||
name='annotations',
|
||||
srcs=['Nullable.java'],
|
||||
visibility=[
|
||||
'PUBLIC'
|
||||
],
|
||||
)
|
@ -1,9 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package genrule.annotations;
|
||||
|
||||
public @interface Nullable {}
|
@ -1,10 +0,0 @@
|
||||
module2/Class2.java, genrule.module2.Class2$Sub.subtypingInconsistency(java.lang.Object):java.lang.Object, 0, ERADICATE_INCONSISTENT_SUBCLASS_PARAMETER_ANNOTATION, no_bucket, WARNING, [First parameter `object` of method `Class2$Sub.subtypingInconsistency(...)` is missing `@Nullable` declaration when overriding `Class1$Sub.subtypingInconsistency(...)`. The parent method declared it can handle `null` for this param, so the child should also declare that.]
|
||||
module2/Class2.java, genrule.module2.Class2$Sub.subtypingInconsistency(java.lang.Object):java.lang.Object, 0, ERADICATE_INCONSISTENT_SUBCLASS_RETURN_ANNOTATION, no_bucket, WARNING, [Child method `Class2$Sub.subtypingInconsistency(...)` is not substitution-compatible with its parent: the return type is declared as nullable, but parent method `Class1$Sub.subtypingInconsistency(...)` is missing `@Nullable` declaration. Either mark the parent as `@Nullable` or ensure the child does not return `null`.]
|
||||
module2/Class2.java, genrule.module2.Class2.dereferenceInterTargetField1Bad(genrule.module1.Class1):void, 0, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [`class1.field1` is nullable and is not locally checked for null when calling `toString()`.]
|
||||
module2/Class2.java, genrule.module2.Class2.dereferenceInterTargetField2Bad(genrule.module1.Class1):int, 0, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [`class1.field2` is nullable and is not locally checked for null when accessing field `Class1.x`.]
|
||||
module2/Class2.java, genrule.module2.Class2.dereferenceLocalNullableFieldBad():void, 0, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [`Class2.field` is nullable and is not locally checked for null when calling `toString()`.]
|
||||
module2/Class2.java, genrule.module2.Class2.followMethodDeclarationOnlyBad(genrule.module1.SkipImplementationClass1):void, 1, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [`obj2` is nullable and is not locally checked for null when calling `toString()`: call to annotatedNullable() at line 39.]
|
||||
module2/Class2.java, genrule.module2.Class2.interTargetAbstractNPEBad(genrule.module1.Class1):void, 1, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [`obj` is nullable and is not locally checked for null when calling `toString()`: call to abstractMayReturnNull() at line 29.]
|
||||
module2/Class2.java, genrule.module2.Class2.interTargetNPEBad():void, 1, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [`obj` is nullable and is not locally checked for null when calling `toString()`: call to returnsNull() at line 24.]
|
||||
module2/Class2.java, genrule.module2.Class2.interTargetNativeNPEBad(genrule.module1.Class1):void, 1, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [`obj` is nullable and is not locally checked for null when calling `toString()`: call to nativeMayReturnNull() at line 34.]
|
||||
module2/Class2.java, genrule.module2.Class2.localNPE2Bad():void, 1, ERADICATE_NULLABLE_DEREFERENCE, no_bucket, WARNING, [NullPointerException will be thrown at this line! `obj` is `null` and is dereferenced via calling `toString()`: null constant at line 19.]
|
@ -1,10 +0,0 @@
|
||||
java_library(
|
||||
name='module1',
|
||||
srcs=glob(["*.java"]),
|
||||
deps=[
|
||||
'//annotations:annotations',
|
||||
],
|
||||
visibility=[
|
||||
'PUBLIC'
|
||||
],
|
||||
)
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package genrule.module1;
|
||||
|
||||
import genrule.annotations.Nullable;
|
||||
|
||||
public abstract class Class1 {
|
||||
|
||||
public @Nullable Object field1;
|
||||
|
||||
public int x;
|
||||
public @Nullable Class1 field2;
|
||||
|
||||
public static @Nullable String returnsNull() {
|
||||
return null;
|
||||
}
|
||||
|
||||
void localNPE1() {
|
||||
Object obj = null;
|
||||
obj.toString();
|
||||
}
|
||||
|
||||
public abstract @Nullable Object abstractMayReturnNull();
|
||||
|
||||
public native @Nullable Object nativeMayReturnNull();
|
||||
|
||||
public Object unannotatedReturnNull() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class Sub {
|
||||
public Object subtypingInconsistency(@Nullable Object object) {
|
||||
return new Object();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// _SHOULD_SKIP_IMPLEMENTATION_
|
||||
|
||||
package genrule.module1;
|
||||
|
||||
import genrule.annotations.Nullable;
|
||||
|
||||
public class SkipImplementationClass1 {
|
||||
|
||||
public @Nullable Object annotatedNullable() {
|
||||
return new Object();
|
||||
}
|
||||
|
||||
public Object notAnnotatedNullable() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
java_library(
|
||||
name='module2',
|
||||
srcs=glob(["*.java"]),
|
||||
deps=[
|
||||
'//module1:module1',
|
||||
'//annotations:annotations',
|
||||
]
|
||||
)
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package genrule.module2;
|
||||
|
||||
import genrule.annotations.Nullable;
|
||||
import genrule.module1.Class1;
|
||||
import genrule.module1.SkipImplementationClass1;
|
||||
|
||||
public class Class2 {
|
||||
|
||||
@Nullable Object field;
|
||||
|
||||
void localNPE2Bad() {
|
||||
Object obj = null;
|
||||
obj.toString();
|
||||
}
|
||||
|
||||
void interTargetNPEBad() {
|
||||
Object obj = Class1.returnsNull();
|
||||
obj.toString();
|
||||
}
|
||||
|
||||
void interTargetAbstractNPEBad(Class1 class1) {
|
||||
Object obj = class1.abstractMayReturnNull();
|
||||
obj.toString();
|
||||
}
|
||||
|
||||
void interTargetNativeNPEBad(Class1 class1) {
|
||||
Object obj = class1.nativeMayReturnNull();
|
||||
obj.toString();
|
||||
}
|
||||
|
||||
void followMethodDeclarationOnlyBad(SkipImplementationClass1 obj1) {
|
||||
Object obj2 = obj1.annotatedNullable();
|
||||
obj2.toString();
|
||||
}
|
||||
|
||||
void followMethodDeclarationOnlyOk(SkipImplementationClass1 obj1) {
|
||||
Object obj2 = obj1.notAnnotatedNullable();
|
||||
obj2.toString();
|
||||
}
|
||||
|
||||
void dereferenceLocalNullableFieldBad() {
|
||||
field.toString();
|
||||
}
|
||||
|
||||
void dereferenceInterTargetField1Bad(Class1 class1) {
|
||||
class1.field1.toString();
|
||||
}
|
||||
|
||||
int dereferenceInterTargetField2Bad(Class1 class1) {
|
||||
return class1.field2.x;
|
||||
}
|
||||
|
||||
void dereferenceUnannotatedMethodReturningNullBad(Class1 class1) {
|
||||
class1.unannotatedReturnNull().toString();
|
||||
}
|
||||
|
||||
static class Sub extends Class1.Sub {
|
||||
@Override
|
||||
public @Nullable Object subtypingInconsistency(Object object) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue