diff --git a/infer/models/java/src/com/google/common/collect/ImmutableList.java b/infer/models/java/src/com/google/common/collect/ImmutableList.java new file mode 100644 index 000000000..2853ca5fa --- /dev/null +++ b/infer/models/java/src/com/google/common/collect/ImmutableList.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.google.common.collect; + +public abstract class ImmutableList { + + public static final class Builder { + + void dereference(Object object) { + object.hashCode(); + } + + public Builder add(E element) { + dereference(element); + return new Builder<>(); + } + + public Builder add(E... elements) { + dereference(elements); + return new Builder<>(); + } + } +} diff --git a/infer/tests/build_systems/ant/build.xml b/infer/tests/build_systems/ant/build.xml index 6511b884e..64430e7ca 100644 --- a/infer/tests/build_systems/ant/build.xml +++ b/infer/tests/build_systems/ant/build.xml @@ -10,12 +10,11 @@ - - + diff --git a/infer/tests/build_systems/ant/issues.exp b/infer/tests/build_systems/ant/issues.exp index 0dd273d8a..957cb90e0 100644 --- a/infer/tests/build_systems/ant/issues.exp +++ b/infer/tests/build_systems/ant/issues.exp @@ -115,6 +115,7 @@ codetoanalyze/java/infer/NullPointerExceptions.java, int NullPointerExceptions.n codetoanalyze/java/infer/NullPointerExceptions.java, int NullPointerExceptions.nullPointerExceptionWithExceptionHandling(boolean), 5, NULL_DEREFERENCE, [start of procedure nullPointerExceptionWithExceptionHandling(...),exception java.lang.Exception,Switch condition is true. Entering switch case] codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions$$$Class$Name$With$Dollars.npeWithDollars(), 2, NULL_DEREFERENCE, [start of procedure npeWithDollars()] codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions$E.dereferenceNullableInterfaceFieldBad(), 1, NULL_DEREFERENCE, [start of procedure dereferenceNullableInterfaceFieldBad()] +codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions.addNullToImmutableListBuilderBad(), 2, NULL_DEREFERENCE, [start of procedure addNullToImmutableListBuilderBad(),Skipping builder(): unknown method,start of procedure getObject(),return from a call to Object NullPointerExceptions.getObject()] codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions.badCheckShouldCauseNPE(), 1, NULL_DEREFERENCE, [start of procedure badCheckShouldCauseNPE(),start of procedure getBool(),Skipping test(): method has no implementation,Definition of test(),Taking true branch,return from a call to Boolean NullPointerExceptions.getBool(),Taking true branch,start of procedure getObj(),Skipping test(): method has no implementation,Definition of test(),Taking false branch,return from a call to Object NullPointerExceptions.getObj()] codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions.cursorFromContentResolverNPE(String), 9, NULL_DEREFERENCE, [start of procedure cursorFromContentResolverNPE(...)] codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions.deferenceNullableMethodCallingSkippedMethodBad(), 1, NULL_DEREFERENCE, [start of procedure deferenceNullableMethodCallingSkippedMethodBad(),start of procedure wrapUnknownFuncWithNullable(),Skipping unknownFunc(): method has no implementation,Definition of unknownFunc(),return from a call to Object NullPointerExceptions.wrapUnknownFuncWithNullable()] diff --git a/infer/tests/codetoanalyze/java/infer/NullPointerExceptions.java b/infer/tests/codetoanalyze/java/infer/NullPointerExceptions.java index c403833d8..f483fd315 100644 --- a/infer/tests/codetoanalyze/java/infer/NullPointerExceptions.java +++ b/infer/tests/codetoanalyze/java/infer/NullPointerExceptions.java @@ -645,4 +645,12 @@ public class NullPointerExceptions { } + Object getObject() { + return null; + } + + void addNullToImmutableListBuilderBad() { + ImmutableList.Builder listBuilder = ImmutableList.builder(); + listBuilder.add(getObject()); + } } diff --git a/infer/tests/codetoanalyze/java/infer/issues.exp b/infer/tests/codetoanalyze/java/infer/issues.exp index dc6f2d593..f7a3fa741 100644 --- a/infer/tests/codetoanalyze/java/infer/issues.exp +++ b/infer/tests/codetoanalyze/java/infer/issues.exp @@ -125,6 +125,7 @@ codetoanalyze/java/infer/NullPointerExceptions.java, int NullPointerExceptions.p codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions$$$Class$Name$With$Dollars.npeWithDollars(), 2, NULL_DEREFERENCE, [start of procedure npeWithDollars()] codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions$E.dereferenceNullableInterfaceFieldBad(), 1, NULL_DEREFERENCE, [start of procedure dereferenceNullableInterfaceFieldBad()] codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions.FP_noNullPointerExceptionAfterSkipFunction(), 4, NULL_DEREFERENCE, [start of procedure FP_noNullPointerExceptionAfterSkipFunction(),Skipping String(...): unknown method,Skipping toString(): unknown method,start of procedure genericMethodSomewhereCheckingForNull(...),Taking true branch,return from a call to void NullPointerExceptions.genericMethodSomewhereCheckingForNull(String)] +codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions.addNullToImmutableListBuilderBad(), 2, NULL_DEREFERENCE, [start of procedure addNullToImmutableListBuilderBad(),Skipping builder(): unknown method,start of procedure getObject(),return from a call to Object NullPointerExceptions.getObject()] codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions.badCheckShouldCauseNPE(), 1, NULL_DEREFERENCE, [start of procedure badCheckShouldCauseNPE(),start of procedure getBool(),Skipping test(): method has no implementation,Definition of test(),Taking true branch,return from a call to Boolean NullPointerExceptions.getBool(),Taking true branch,start of procedure getObj(),Skipping test(): method has no implementation,Definition of test(),Taking false branch,return from a call to Object NullPointerExceptions.getObj()] codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions.cursorFromContentResolverNPE(String), 9, NULL_DEREFERENCE, [start of procedure cursorFromContentResolverNPE(...)] codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions.deferenceNullableMethodCallingSkippedMethodBad(), 1, NULL_DEREFERENCE, [start of procedure deferenceNullableMethodCallingSkippedMethodBad(),start of procedure wrapUnknownFuncWithNullable(),Skipping unknownFunc(): method has no implementation,Definition of unknownFunc(),return from a call to Object NullPointerExceptions.wrapUnknownFuncWithNullable()] diff --git a/infer/tests/codetoanalyze/java/tracing/issues.exp b/infer/tests/codetoanalyze/java/tracing/issues.exp index c97de1db3..8bee3444a 100644 --- a/infer/tests/codetoanalyze/java/tracing/issues.exp +++ b/infer/tests/codetoanalyze/java/tracing/issues.exp @@ -13,6 +13,8 @@ codetoanalyze/java/infer/NullPointerExceptions.java, int NullPointerExceptions.n codetoanalyze/java/infer/NullPointerExceptions.java, int NullPointerExceptions.nullPointerExceptionWithExceptionHandling(boolean), 5, java.lang.NullPointerException, [start of procedure nullPointerExceptionWithExceptionHandling(...),Taking true branch,exception java.lang.Exception,Switch condition is true. Entering switch case,exception java.lang.NullPointerException,return from a call to int NullPointerExceptions.nullPointerExceptionWithExceptionHandling(boolean)] codetoanalyze/java/infer/NullPointerExceptions.java, int NullPointerExceptions.preconditionCheckStateTest(NullPointerExceptions$D), 1, PRECONDITION_NOT_MET, [start of procedure preconditionCheckStateTest(...),Taking false branch] codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions$$$Class$Name$With$Dollars.npeWithDollars(), 3, java.lang.NullPointerException, [start of procedure npeWithDollars(),exception java.lang.NullPointerException,return from a call to void NullPointerExceptions$$$Class$Name$With$Dollars.npeWithDollars()] +codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions.addNullToImmutableListBuilderBad(), 2, NULL_DEREFERENCE, [start of procedure addNullToImmutableListBuilderBad(),Skipping builder(): unknown method,start of procedure getObject(),return from a call to Object NullPointerExceptions.getObject(),Taking true branch] +codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions.addNullToImmutableListBuilderBad(), 3, java.lang.NullPointerException, [start of procedure addNullToImmutableListBuilderBad(),Skipping builder(): unknown method,start of procedure getObject(),return from a call to Object NullPointerExceptions.getObject(),exception java.lang.NullPointerException,return from a call to void NullPointerExceptions.addNullToImmutableListBuilderBad()] codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions.badCheckShouldCauseNPE(), 2, java.lang.NullPointerException, [start of procedure badCheckShouldCauseNPE(),start of procedure getBool(),Skipping test(): method has no implementation,Definition of test(),Taking true branch,return from a call to Boolean NullPointerExceptions.getBool(),Taking true branch,start of procedure getObj(),Skipping test(): method has no implementation,Definition of test(),Taking true branch,return from a call to Object NullPointerExceptions.getObj(),Taking true branch,return from a call to void NullPointerExceptions.badCheckShouldCauseNPE()] codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions.deferenceNullableMethodCallingSkippedMethodBad(), 2, java.lang.NullPointerException, [start of procedure deferenceNullableMethodCallingSkippedMethodBad(),start of procedure wrapUnknownFuncWithNullable(),Skipping unknownFunc(): method has no implementation,Definition of unknownFunc(),return from a call to Object NullPointerExceptions.wrapUnknownFuncWithNullable(),Taking true branch,return from a call to void NullPointerExceptions.deferenceNullableMethodCallingSkippedMethodBad()] codetoanalyze/java/infer/NullPointerExceptions.java, void NullPointerExceptions.derefNonThisGetterAfterCheckShouldNotCauseNPE(), 5, java.lang.NullPointerException, [start of procedure derefNonThisGetterAfterCheckShouldNotCauseNPE(),start of procedure NullPointerExceptions(),return from a call to NullPointerExceptions.(),Taking true branch,start of procedure getObj(),Skipping test(): method has no implementation,Definition of test(),Taking true branch,return from a call to Object NullPointerExceptions.getObj(),Taking true branch,Taking true branch,start of procedure getObj(),Skipping test(): method has no implementation,Definition of test(),Taking true branch,return from a call to Object NullPointerExceptions.getObj(),Taking true branch,return from a call to void NullPointerExceptions.derefNonThisGetterAfterCheckShouldNotCauseNPE()]