Reviewed By: cristianoc Differential Revision: D4325120 fbshipit-source-id: 8af01d3master
parent
5ab1a62aa2
commit
cd1c9750f4
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 java.util;
|
||||
|
||||
import com.facebook.infer.builtins.InferUndefined;
|
||||
|
||||
// could make List an abstract class directly instead, but that breaks other models
|
||||
public abstract class AbstractList<T> extends AbstractCollection<T> implements List<T> {
|
||||
|
||||
// need three-value state for unknown (-1), false (0), or true (1)
|
||||
// the reason we can't use a bool is that we want to return either true or false each time we call
|
||||
// isEmpty, and we want to get the same result each time
|
||||
private int mIsEmpty;
|
||||
|
||||
native T any();
|
||||
|
||||
public AbstractList() {
|
||||
mIsEmpty = 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
if (mIsEmpty < 0) {
|
||||
if (InferUndefined.boolean_undefined()) {
|
||||
mIsEmpty = 1;
|
||||
} else {
|
||||
mIsEmpty = 0;
|
||||
}
|
||||
}
|
||||
return mIsEmpty == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, T toAdd) {
|
||||
mIsEmpty = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove(int index) {
|
||||
mIsEmpty = -1;
|
||||
return any();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
boolean result = InferUndefined.boolean_undefined();
|
||||
if (result) {
|
||||
mIsEmpty = -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
mIsEmpty = 1;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2016 - 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 java.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
// abstract so we don't have to implement every method of List
|
||||
public abstract class ArrayList<T>
|
||||
extends AbstractList<T>
|
||||
implements List<T>, RandomAccess, Cloneable, Serializable {
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return super.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, T toAdd) {
|
||||
super.add(index, toAdd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove(int index) {
|
||||
return super.remove(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
return super.remove(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2016 - 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 java.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
// abstract so we don't have to implement every method of List
|
||||
public abstract class LinkedList<T>
|
||||
extends AbstractSequentialList<T>
|
||||
implements Serializable, Cloneable, Iterable<T>, Collection<T>, Deque<T>, List<T>, Queue<T> {
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return super.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, T toAdd) {
|
||||
super.add(index, toAdd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove(int index) {
|
||||
return super.remove(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
return super.remove(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2016 - 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 codetoanalyze.java.infer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class Lists {
|
||||
|
||||
void emptyRemembersOk(List l) {
|
||||
boolean empty = l.isEmpty();
|
||||
Object o = null;
|
||||
if (empty != l.isEmpty()) {
|
||||
o.toString();
|
||||
}
|
||||
}
|
||||
|
||||
void removeInvalidatesNonEmptinessNPE(List l, int i) {
|
||||
if (!l.isEmpty()) {
|
||||
l.remove(i);
|
||||
Object o = null;
|
||||
if (l.isEmpty()) {
|
||||
o.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void clearCausesEmptinessNPE(List l, int i) {
|
||||
if (!l.isEmpty()) {
|
||||
l.clear();
|
||||
Object o = null;
|
||||
if (l.isEmpty()) {
|
||||
o.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// it would be too noisy to report here
|
||||
void plainGetOk(List l, int i) {
|
||||
l.get(i).toString();
|
||||
}
|
||||
|
||||
Object getElement(List l) {
|
||||
return l.isEmpty() ? null : l.get(0);
|
||||
}
|
||||
|
||||
void getElementOk(List l) {
|
||||
if (l.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
getElement(l).toString();
|
||||
}
|
||||
|
||||
void getElementNPE(List l) {
|
||||
if (!l.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
getElement(l).toString();
|
||||
}
|
||||
|
||||
// don't fully understand why we don't get this one; model should allow it
|
||||
void FN_addInvalidatesEmptinessNPE(List l) {
|
||||
if (l.isEmpty()) {
|
||||
l.add(0, new Object());
|
||||
Object o = null;
|
||||
if (!l.isEmpty()) {
|
||||
o.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue