From 61d75d9991b2cfab56b59df9a0c31533d608a750 Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Mon, 17 Dec 2018 20:47:26 -0800 Subject: [PATCH] [infer][nullsafe] use the same human readable error message for Eradicate and the new Nullsafe backend Reviewed By: mbouaziz Differential Revision: D13414508 fbshipit-source-id: 06a366177 --- infer/src/base/IssueType.ml | 4 +++- infer/src/base/IssueType.mli | 2 +- infer/src/nullsafe/NullabilitySuggest.ml | 2 +- infer/tests/codetoanalyze/cpp/nullable/issues.exp | 12 ++++++------ infer/tests/codetoanalyze/java/checkers/issues.exp | 12 ++++++------ infer/tests/codetoanalyze/objc/nullable/issues.exp | 14 +++++++------- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/infer/src/base/IssueType.ml b/infer/src/base/IssueType.ml index 33ca51d03..68d20fcd1 100644 --- a/infer/src/base/IssueType.ml +++ b/infer/src/base/IssueType.ml @@ -254,7 +254,9 @@ let expensive_execution_time_call = from_string ~enabled:false "EXPENSIVE_EXECUT let failure_exe = from_string "Failure_exe" -let field_should_be_nullable = from_string "FIELD_SHOULD_BE_NULLABLE" +let nullsafe_field_not_nullable = + from_string "NULLSAFE_FIELD_NOT_NULLABLE" ~hum:"Field Not Nullable" + let field_not_null_checked = from_string "IVAR_NOT_NULL_CHECKED" diff --git a/infer/src/base/IssueType.mli b/infer/src/base/IssueType.mli index 500f9ce4f..05ca9835f 100644 --- a/infer/src/base/IssueType.mli +++ b/infer/src/base/IssueType.mli @@ -167,7 +167,7 @@ val expensive_execution_time_call : t val failure_exe : t -val field_should_be_nullable : t +val nullsafe_field_not_nullable : t val field_not_null_checked : t diff --git a/infer/src/nullsafe/NullabilitySuggest.ml b/infer/src/nullsafe/NullabilitySuggest.ml index 18ceee2bb..16901595b 100644 --- a/infer/src/nullsafe/NullabilitySuggest.ml +++ b/infer/src/nullsafe/NullabilitySuggest.ml @@ -204,7 +204,7 @@ let checker {Callbacks.summary; proc_desc; tenv} = | None -> (Procdesc.get_loc proc_desc, None) in - Reporting.log_warning summary ~loc ?ltr IssueType.field_should_be_nullable message + Reporting.log_warning summary ~loc ?ltr IssueType.nullsafe_field_not_nullable message | _ -> () in diff --git a/infer/tests/codetoanalyze/cpp/nullable/issues.exp b/infer/tests/codetoanalyze/cpp/nullable/issues.exp index 37b3159c3..6dd53a434 100644 --- a/infer/tests/codetoanalyze/cpp/nullable/issues.exp +++ b/infer/tests/codetoanalyze/cpp/nullable/issues.exp @@ -1,12 +1,12 @@ -codetoanalyze/cpp/nullable/example.cpp, T_FP_dereference_nonnull_field_after_test_for_null_okay, 1, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field nonnull_field is compared to null here] +codetoanalyze/cpp/nullable/example.cpp, T_FP_dereference_nonnull_field_after_test_for_null_okay, 1, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field nonnull_field is compared to null here] codetoanalyze/cpp/nullable/example.cpp, T_FP_dereference_nonnull_field_after_test_for_null_okay, 2, NULL_DEREFERENCE, B5, ERROR, [start of procedure FP_dereference_nonnull_field_after_test_for_null_okay,Taking true branch] -codetoanalyze/cpp/nullable/example.cpp, T_assign_nonnull_field_to_null_bad, 0, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field nonnull_field is assigned null here] -codetoanalyze/cpp/nullable/example.cpp, T_assign_unnanotated_field_to_null_bad, 0, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field unnanotated_field is assigned null here] +codetoanalyze/cpp/nullable/example.cpp, T_assign_nonnull_field_to_null_bad, 0, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field nonnull_field is assigned null here] +codetoanalyze/cpp/nullable/example.cpp, T_assign_unnanotated_field_to_null_bad, 0, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field unnanotated_field is assigned null here] codetoanalyze/cpp/nullable/example.cpp, T_dereference_nullable_field_bad, 0, NULL_DEREFERENCE, B1, ERROR, [start of procedure dereference_nullable_field_bad] -codetoanalyze/cpp/nullable/example.cpp, T_dereference_unnanotated_field_after_test_for_null_bad, 1, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field unnanotated_field is compared to null here] +codetoanalyze/cpp/nullable/example.cpp, T_dereference_unnanotated_field_after_test_for_null_bad, 1, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field unnanotated_field is compared to null here] codetoanalyze/cpp/nullable/example.cpp, T_dereference_unnanotated_field_after_test_for_null_bad, 2, NULL_DEREFERENCE, B5, ERROR, [start of procedure dereference_unnanotated_field_after_test_for_null_bad,Taking true branch] -codetoanalyze/cpp/nullable/example.cpp, T_test_nonnull_field_for_null_bad, 1, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field nonnull_field is compared to null here] -codetoanalyze/cpp/nullable/example.cpp, T_test_unnanotated_field_for_null_bad, 1, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field unnanotated_field is compared to null here] +codetoanalyze/cpp/nullable/example.cpp, T_test_nonnull_field_for_null_bad, 1, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field nonnull_field is compared to null here] +codetoanalyze/cpp/nullable/example.cpp, T_test_unnanotated_field_for_null_bad, 1, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field unnanotated_field is compared to null here] codetoanalyze/cpp/nullable/method.cpp, assignNullableValueBad, 2, NULLABLE_DEREFERENCE, no_bucket, ERROR, [dereference of p,assignment of the nullable value,definition of mayReturnNullPointer] codetoanalyze/cpp/nullable/method.cpp, assignNullableValueBad, 2, NULL_DEREFERENCE, B2, ERROR, [start of procedure assignNullableValueBad(),start of procedure mayReturnNullPointer,Taking true branch,return from a call to T_mayReturnNullPointer] codetoanalyze/cpp/nullable/method.cpp, avoidDoubleReportingBad, 2, NULLABLE_DEREFERENCE, no_bucket, ERROR, [dereference of p,assignment of the nullable value,definition of mayReturnNullObject] diff --git a/infer/tests/codetoanalyze/java/checkers/issues.exp b/infer/tests/codetoanalyze/java/checkers/issues.exp index 95360d260..cb26c41b1 100644 --- a/infer/tests/codetoanalyze/java/checkers/issues.exp +++ b/infer/tests/codetoanalyze/java/checkers/issues.exp @@ -33,12 +33,12 @@ codetoanalyze/java/checkers/ImmutableCast.java, codetoanalyze.java.checkers.Immu codetoanalyze/java/checkers/ImmutableCast.java, codetoanalyze.java.checkers.ImmutableCast.badCastFromField():java.util.List, 0, CHECKERS_IMMUTABLE_CAST, no_bucket, WARNING, [Method badCastFromField() returns class com.google.common.collect.ImmutableList but the return type is class java.util.List. Make sure that users of this method do not try to modify the collection.] codetoanalyze/java/checkers/NoAllocationExample.java, codetoanalyze.java.checkers.NoAllocationExample.directlyAllocatingMethod():void, 1, CHECKERS_ALLOCATES_MEMORY, no_bucket, ERROR, [] codetoanalyze/java/checkers/NoAllocationExample.java, codetoanalyze.java.checkers.NoAllocationExample.indirectlyAllocatingMethod():void, 1, CHECKERS_ALLOCATES_MEMORY, no_bucket, ERROR, [] -codetoanalyze/java/checkers/NullableSuggest.java, codetoanalyze.java.checkers.NullableSuggest.assignNullBad():void, 1, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field obj0 is assigned null here] -codetoanalyze/java/checkers/NullableSuggest.java, codetoanalyze.java.checkers.NullableSuggest.assignNullToFieldInOtherClassBad():void, 2, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field obj2 is assigned null here] -codetoanalyze/java/checkers/NullableSuggest.java, codetoanalyze.java.checkers.NullableSuggest.assignNullToFieldTransitiveBad(boolean):void, 3, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field obj0 could be assigned here,Variable could be assigned here,Variable could be assigned here,Variable is assigned null here] -codetoanalyze/java/checkers/NullableSuggest.java, codetoanalyze.java.checkers.NullableSuggest.assignNullToFieldTransitiveLoopBad(int):void, 7, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field obj0 could be assigned here,Some array element could be assigned here,Variable is assigned null here] -codetoanalyze/java/checkers/NullableSuggest.java, codetoanalyze.java.checkers.NullableSuggest.compareNullToFieldBad():void, 2, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field obj0 is compared to null here] -codetoanalyze/java/checkers/NullableSuggest.java, codetoanalyze.java.checkers.NullableSuggest.multipleChainsAlwaysSelectShortestBad(boolean):void, 6, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field obj0 could be assigned here,Variable is assigned null here] +codetoanalyze/java/checkers/NullableSuggest.java, codetoanalyze.java.checkers.NullableSuggest.assignNullBad():void, 1, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field obj0 is assigned null here] +codetoanalyze/java/checkers/NullableSuggest.java, codetoanalyze.java.checkers.NullableSuggest.assignNullToFieldInOtherClassBad():void, 2, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field obj2 is assigned null here] +codetoanalyze/java/checkers/NullableSuggest.java, codetoanalyze.java.checkers.NullableSuggest.assignNullToFieldTransitiveBad(boolean):void, 3, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field obj0 could be assigned here,Variable could be assigned here,Variable could be assigned here,Variable is assigned null here] +codetoanalyze/java/checkers/NullableSuggest.java, codetoanalyze.java.checkers.NullableSuggest.assignNullToFieldTransitiveLoopBad(int):void, 7, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field obj0 could be assigned here,Some array element could be assigned here,Variable is assigned null here] +codetoanalyze/java/checkers/NullableSuggest.java, codetoanalyze.java.checkers.NullableSuggest.compareNullToFieldBad():void, 2, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field obj0 is compared to null here] +codetoanalyze/java/checkers/NullableSuggest.java, codetoanalyze.java.checkers.NullableSuggest.multipleChainsAlwaysSelectShortestBad(boolean):void, 6, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field obj0 could be assigned here,Variable is assigned null here] codetoanalyze/java/checkers/NullableViolation.java, codetoanalyze.java.checkers.NullableViolation.dereferenceNullableMethodBad():void, 1, NULLABLE_DEREFERENCE, no_bucket, ERROR, [dereferencing the return of NullableViolation.returnsNullable(),definition of returnsNullable] codetoanalyze/java/checkers/NullableViolation.java, codetoanalyze.java.checkers.NullableViolation.dereferenceNullableMethodInElseBranchBad():void, 3, NULLABLE_DEREFERENCE, no_bucket, ERROR, [dereferencing the return of NullableViolation.returnsNullable(),definition of returnsNullable] codetoanalyze/java/checkers/NullableViolation.java, codetoanalyze.java.checkers.NullableViolation.dereferenceNullableMethodIncorrectlyCheckedForNullBad():void, 2, NULLABLE_DEREFERENCE, no_bucket, ERROR, [dereferencing the return of NullableViolation.returnsNullable(),definition of returnsNullable] diff --git a/infer/tests/codetoanalyze/objc/nullable/issues.exp b/infer/tests/codetoanalyze/objc/nullable/issues.exp index eeaddedc1..9ece1c9ac 100644 --- a/infer/tests/codetoanalyze/objc/nullable/issues.exp +++ b/infer/tests/codetoanalyze/objc/nullable/issues.exp @@ -1,11 +1,11 @@ -codetoanalyze/objc/nullable/Examples.m, T_FP_dereferenceNonnullFieldAfterTestForNullOkay, 1, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field nonnullField is compared to null here] +codetoanalyze/objc/nullable/Examples.m, T_FP_dereferenceNonnullFieldAfterTestForNullOkay, 1, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field nonnullField is compared to null here] codetoanalyze/objc/nullable/Examples.m, T_addNullableObjectInMutableArrayBad, 2, NULLABLE_DEREFERENCE, no_bucket, ERROR, [dereferencing the return of nullableMethod,assignment of the nullable value,definition of nullableMethod] -codetoanalyze/objc/nullable/Examples.m, T_assignNonnullFieldToNullBad, 1, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field nonnullField is assigned null here] -codetoanalyze/objc/nullable/Examples.m, T_assignUnnanotatedFieldToNullBad, 1, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field unnanotatedField is assigned null here] +codetoanalyze/objc/nullable/Examples.m, T_assignNonnullFieldToNullBad, 1, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field nonnullField is assigned null here] +codetoanalyze/objc/nullable/Examples.m, T_assignUnnanotatedFieldToNullBad, 1, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field unnanotatedField is assigned null here] codetoanalyze/objc/nullable/Examples.m, T_createArrayByAddingNilBad, 2, NULLABLE_DEREFERENCE, no_bucket, ERROR, [dereferencing the return of nullableMethod,assignment of the nullable value,definition of nullableMethod] codetoanalyze/objc/nullable/Examples.m, T_dereferenceNullableFunctionBad, 2, NULLABLE_DEREFERENCE, no_bucket, ERROR, [dereference of p,assignment of the nullable value,definition of returnsNull] codetoanalyze/objc/nullable/Examples.m, T_dereferenceNullableLibraryMethodBad:, 2, NULLABLE_DEREFERENCE, no_bucket, ERROR, [dereference of nullableObject,assignment of the nullable value,definition of nullableLibraryMethod] -codetoanalyze/objc/nullable/Examples.m, T_dereferenceUnnanotatedFieldAfterTestForNullBad, 1, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field unnanotatedField is compared to null here] +codetoanalyze/objc/nullable/Examples.m, T_dereferenceUnnanotatedFieldAfterTestForNullBad, 1, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field unnanotatedField is compared to null here] codetoanalyze/objc/nullable/Examples.m, T_indirectNullableKeyInNSDictionaryBad, 3, NULLABLE_DEREFERENCE, no_bucket, ERROR, [dereference of nullableKeyString,assignment of the nullable value,definition of nullableMethod] codetoanalyze/objc/nullable/Examples.m, T_insertNullableObjectInMutableArrayBad, 2, NULLABLE_DEREFERENCE, no_bucket, ERROR, [dereferencing the return of nullableMethod,assignment of the nullable value,definition of nullableMethod] codetoanalyze/objc/nullable/Examples.m, T_nullableKeyInNSDictionaryBad, 2, NULLABLE_DEREFERENCE, no_bucket, ERROR, [dereference of nullableKey,assignment of the nullable value,definition of nullableMethod] @@ -20,7 +20,7 @@ codetoanalyze/objc/nullable/Examples.m, T_propagateNullabilityOnMethodCallBad, 4 codetoanalyze/objc/nullable/Examples.m, T_secondElementNullableObjectInNSArrayBad, 3, NULLABLE_DEREFERENCE, no_bucket, ERROR, [dereference of nullableObject,assignment of the nullable value,definition of nullableMethod] codetoanalyze/objc/nullable/Examples.m, T_setNullableObjectInDictionaryBad, 2, NULLABLE_DEREFERENCE, no_bucket, ERROR, [dereferencing the return of nullableMethod,assignment of the nullable value,definition of nullableMethod] codetoanalyze/objc/nullable/Examples.m, T_shouldPropagateNullabilityOnPointerTypeBad, 3, NULLABLE_DEREFERENCE, no_bucket, ERROR, [dereference of s,assignment of the nullable value,definition of nullableT] -codetoanalyze/objc/nullable/Examples.m, T_testNonnullFieldForNullBad, 1, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field nonnullField is compared to null here] -codetoanalyze/objc/nullable/Examples.m, T_testUnnanotatedFieldForNullBad, 1, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field unnanotatedField is compared to null here] +codetoanalyze/objc/nullable/Examples.m, T_testNonnullFieldForNullBad, 1, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field nonnullField is compared to null here] +codetoanalyze/objc/nullable/Examples.m, T_testUnnanotatedFieldForNullBad, 1, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field unnanotatedField is compared to null here] codetoanalyze/objc/nullable/Examples.m, callNullableMethodFromProtocolBad, 2, NULLABLE_DEREFERENCE, no_bucket, ERROR, [dereference of nullableObject,assignment of the nullable value,definition of nullableMethod] -codetoanalyze/objc/nullable/Examples.m, objc_blockT_DeadStoreFP_testUnnanotatedFieldInClosureBad_1, 1, FIELD_SHOULD_BE_NULLABLE, no_bucket, WARNING, [Field unnanotatedField is compared to null here] +codetoanalyze/objc/nullable/Examples.m, objc_blockT_DeadStoreFP_testUnnanotatedFieldInClosureBad_1, 1, NULLSAFE_FIELD_NOT_NULLABLE, no_bucket, WARNING, [Field unnanotatedField is compared to null here]