optional model

Reviewed By: jvillard

Differential Revision: D3400635

fbshipit-source-id: 2078050
master
Peter O'Hearn 9 years ago committed by Facebook Github Bot 7
parent d707c717f0
commit 508d6a3ae7

@ -0,0 +1,19 @@
/*
* Copyright (c) 2013 - 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.base;
import javax.annotation.Nullable;
public abstract class Optional<T> {
@Nullable
public abstract T orNull();
}

@ -649,6 +649,11 @@
"file": "codetoanalyze/java/infer/ResourceLeaks.java", "file": "codetoanalyze/java/infer/ResourceLeaks.java",
"procedure": "void ResourceLeaks.openHttpsURLConnectionNotDisconnected()" "procedure": "void ResourceLeaks.openHttpsURLConnectionNotDisconnected()"
}, },
{
"bug_type": "NULL_DEREFERENCE",
"file": "codetoanalyze/java/infer/NullPointerExceptions.java",
"procedure": "void NullPointerExceptions.optionalNPE(Optional)"
},
{ {
"bug_type": "NULL_DEREFERENCE", "bug_type": "NULL_DEREFERENCE",
"file": "codetoanalyze/java/infer/NullPointerExceptions.java", "file": "codetoanalyze/java/infer/NullPointerExceptions.java",

@ -649,6 +649,11 @@
"file": "infer/tests/codetoanalyze/java/infer/ResourceLeaks.java", "file": "infer/tests/codetoanalyze/java/infer/ResourceLeaks.java",
"procedure": "void ResourceLeaks.openHttpsURLConnectionNotDisconnected()" "procedure": "void ResourceLeaks.openHttpsURLConnectionNotDisconnected()"
}, },
{
"bug_type": "NULL_DEREFERENCE",
"file": "infer/tests/codetoanalyze/java/infer/NullPointerExceptions.java",
"procedure": "void NullPointerExceptions.optionalNPE(Optional)"
},
{ {
"bug_type": "NULL_DEREFERENCE", "bug_type": "NULL_DEREFERENCE",
"file": "infer/tests/codetoanalyze/java/infer/NullPointerExceptions.java", "file": "infer/tests/codetoanalyze/java/infer/NullPointerExceptions.java",

@ -15,6 +15,7 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils; import android.text.TextUtils;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -558,4 +559,9 @@ public class NullPointerExceptions {
s.toString(); // Expect NPE here s.toString(); // Expect NPE here
} }
void optionalNPE(Optional<Object> o) {
o.orNull().toString();
}
} }

@ -74,6 +74,7 @@ public class NullPointerExceptionTest {
"dereferenceAfterLoopOnList", "dereferenceAfterLoopOnList",
"dereferenceAfterUnlock1", "dereferenceAfterUnlock1",
"dereferenceAfterUnlock2", "dereferenceAfterUnlock2",
"optionalNPE",
}; };
assertThat( assertThat(
"Results should contain " + NULL_DEREFERENCE, "Results should contain " + NULL_DEREFERENCE,

Loading…
Cancel
Save