[infer][java] add model for ImmutableList$Builder.add which crashes when given a null value

Reviewed By: sblackshear

Differential Revision: D6445123

fbshipit-source-id: 418fe41
master
Jeremy Dubreil 7 years ago committed by Facebook Github Bot
parent bff96f1d75
commit 10eef3bb1f

@ -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<E> {
public static final class Builder<E> {
void dereference(Object object) {
object.hashCode();
}
public Builder<E> add(E element) {
dereference(element);
return new Builder<>();
}
public Builder<E> add(E... elements) {
dereference(elements);
return new Builder<>();
}
}
}

@ -10,12 +10,11 @@
<classpath>
<pathelement location="../../../lib/java/android/android-23.jar"/>
<pathelement location="../../../lib/java/android/support/v4/android-support-v4.jar"/>
<pathelement location="../../../lib/java/models.jar"/>
<pathelement location="../../../../dependencies/java/guava/guava-10.0.1-fork.jar"/>
<pathelement location="../../../../dependencies/java/jackson/jackson-2.2.3.jar"/>
<pathelement location="../../../../dependencies/java/jsr-305/jsr305.jar"/>
<pathelement location="../../../annotations/annotations.jar"/>
<pathelement location="../../../lib/java/models.jar"/>
</classpath>
</javac>
</target>

@ -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()]

@ -645,4 +645,12 @@ public class NullPointerExceptions {
}
Object getObject() {
return null;
}
void addNullToImmutableListBuilderBad() {
ImmutableList.Builder<Object> listBuilder = ImmutableList.builder();
listBuilder.add(getObject());
}
}

@ -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()]

@ -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.<init>(),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()]

Loading…
Cancel
Save