Add models of FileChannel.tryLock methods.

Summary: Add models of the java.nio.channels.FileChannel.tryLock methods which can
return null according to the java docs.

public

Reviewed By: sblackshear, cristianoc

Differential Revision: D2650050

fb-gh-sync-id: ae6c8ce
master
Josh Berdine 9 years ago committed by facebook-github-bot-7
parent b77e24fa01
commit bf408a1d03

@ -9,7 +9,8 @@
package java.nio.channels;
import com.facebook.infer.models.InferBuiltins;
import com.facebook.infer.models.InferUndefined;
import javax.annotation.Nullable;
import java.nio.channels.spi.AbstractInterruptibleChannel;
import java.nio.channels.FileLock;
@ -26,6 +27,16 @@ public abstract class FileChannel extends AbstractInterruptibleChannel {
private String displayName;
}
private native FileLock getFileLock();
public @Nullable FileLock tryLock() {
if (InferUndefined.boolean_undefined()) {
return null;
} else {
return (FileLock)InferUndefined.object_undefined();
}
}
public final @Nullable FileLock tryLock(long position, long size, boolean shared) {
return tryLock();
}
}

@ -359,6 +359,11 @@
"file": "codetoanalyze/java/infer/NullPointerExceptions.java",
"bug_type": "NULL_DEREFERENCE"
},
{
"procedure": "String NullPointerExceptions.nullTryLock(FileChannel)",
"file": "codetoanalyze/java/infer/NullPointerExceptions.java",
"bug_type": "NULL_DEREFERENCE"
},
{
"procedure": "void ReaderLeaks.readerNotClosedAfterRead()",
"file": "codetoanalyze/java/infer/ReaderLeaks.java",

@ -559,6 +559,11 @@
"file": "infer/tests/codetoanalyze/java/infer/NullPointerExceptions.java",
"bug_type": "NULL_DEREFERENCE"
},
{
"procedure": "String NullPointerExceptions.nullTryLock(FileChannel)",
"file": "infer/tests/codetoanalyze/java/infer/NullPointerExceptions.java",
"bug_type": "NULL_DEREFERENCE"
},
{
"procedure": "void ContextLeaks.directLeak()",
"file": "infer/tests/codetoanalyze/java/infer/ContextLeaks.java",

@ -24,6 +24,8 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.lang.System;
import java.util.HashMap;
@ -452,4 +454,9 @@ public class NullPointerExceptions {
o.toString();
}
String nullTryLock(FileChannel chan) throws IOException {
FileLock lock = chan.tryLock();
return lock.toString(); // expect possible NullPointerException as lock == null is possible
}
}

@ -65,7 +65,8 @@ public class NullPointerExceptionTest {
"testSystemGetPropertyArgument",
"testSystemGetPropertyReturn",
"derefNull",
"nullListFiles"
"nullListFiles",
"nullTryLock"
};
assertThat(
"Results should contain " + NULL_DEREFERENCE,

Loading…
Cancel
Save