Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions infer/src/pulse/PulseModelsJava.ml
Original file line number Diff line number Diff line change
Expand Up @@ -414,17 +414,6 @@ module Resource = struct

let zip_codec_release = StringSet.of_list ["close"; "end"]

(* [SeekableByteChannel] reads, writes and repositions. None of them closes the channel, and the
ones below may throw [IOException]. Left unknown, any of them makes Pulse drop a channel
returned by [Files.newByteChannel] or [FileChannel.open]. [size], [transferTo] and
[transferFrom] are not included: channels from [getChannel] delegate to a stream, and modeling
those calls changes which delegated stream is still tracked in the existing tests. *)
let byte_channel_usage_modeled_throws_IOException =
StringSet.of_list ["position"; "read"; "truncate"; "write"]


let byte_channel_usage_modeled = StringSet.of_list ["isOpen"]

let use ~exn_class_name : model_no_non_disj =
let exn = JavaClassName.from_string exn_class_name in
fun model_data astate ->
Expand Down Expand Up @@ -1078,27 +1067,6 @@ let matchers : matcher list =
&:: "newBufferedWriter"
<>--> Resource.allocate_returned ~exn_class_name:"java.io.IOException" "java.io.BufferedWriter"
|> with_non_disj
(* [Files.newByteChannel] and [FileChannel.open] return a fresh channel without a modeled
constructor, so the channel was never tracked (same gap as the stream factories, #2110). *)
; +map_context_tenv (PatternMatch.Java.implements "java.nio.file.Files")
&:: "newByteChannel"
<>--> Resource.allocate_returned ~exn_class_name:"java.io.IOException"
"java.nio.channels.SeekableByteChannel"
|> with_non_disj
; +map_context_tenv (PatternMatch.Java.implements "java.nio.channels.FileChannel")
&:: "open"
<>--> Resource.allocate_returned ~exn_class_name:"java.io.IOException"
"java.nio.channels.FileChannel"
|> with_non_disj
; +map_context_tenv (PatternMatch.Java.implements "java.nio.channels.SeekableByteChannel")
&::+ (fun _ proc_name_str ->
StringSet.mem proc_name_str Resource.byte_channel_usage_modeled_throws_IOException )
<>$ any_arg
$+...$--> Resource.use ~exn_class_name:"java.io.IOException"
|> with_non_disj
; +map_context_tenv (PatternMatch.Java.implements "java.nio.channels.SeekableByteChannel")
&::+ (fun _ proc_name_str -> StringSet.mem proc_name_str Resource.byte_channel_usage_modeled)
<>$ any_arg $+...$--> Basic.skip |> with_non_disj
; +map_context_tenv (PatternMatch.Java.implements "java.sql.DriverManager")
&:: "getConnection"
<>--> Resource.allocate_returned ~exn_class_name:"java.sql.SQLException" "java.sql.Connection"
Expand Down
47 changes: 0 additions & 47 deletions infer/tests/codetoanalyze/java/pulse/FilesLeaks.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

// Streams returned by the java.nio.file.Files factories (issue #2110)
public class FilesLeaks {
Expand Down Expand Up @@ -78,47 +74,4 @@ public void newBufferedWriterTryWithResourcesOk(Path path) throws IOException {
writer.write(1);
}
}

// Channels from Files.newByteChannel and FileChannel.open are fresh resources. Left unknown,
// Pulse never allocates them, so not closing the channel is missed.

public void newByteChannelNotClosedAfterReadBad(Path path) throws IOException {
SeekableByteChannel channel = Files.newByteChannel(path);
ByteBuffer buffer = ByteBuffer.allocate(8);
channel.read(buffer);
}

public void newByteChannelClosedOk(Path path) throws IOException {
SeekableByteChannel channel = Files.newByteChannel(path);
try {
ByteBuffer buffer = ByteBuffer.allocate(8);
channel.read(buffer);
} finally {
channel.close();
}
}

public void newByteChannelTryWithResourcesOk(Path path) throws IOException {
try (SeekableByteChannel channel = Files.newByteChannel(path)) {
ByteBuffer buffer = ByteBuffer.allocate(8);
channel.read(buffer);
}
}

public SeekableByteChannel newByteChannelReturnedOk(Path path) throws IOException {
return Files.newByteChannel(path);
}

public void fileChannelOpenNotClosedAfterWriteBad(Path path) throws IOException {
FileChannel channel = FileChannel.open(path, StandardOpenOption.WRITE);
ByteBuffer buffer = ByteBuffer.allocate(8);
channel.write(buffer);
}

public void fileChannelOpenTryWithResourcesOk(Path path) throws IOException {
try (FileChannel channel = FileChannel.open(path, StandardOpenOption.READ)) {
ByteBuffer buffer = ByteBuffer.allocate(8);
channel.read(buffer);
}
}
}
4 changes: 0 additions & 4 deletions infer/tests/codetoanalyze/java/pulse/issues.exp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ codetoanalyze/java/pulse/FilesLeaks.java, codetoanalyze.java.infer.FilesLeaks.ne
codetoanalyze/java/pulse/FilesLeaks.java, codetoanalyze.java.infer.FilesLeaks.newBufferedReaderNotClosedAfterReadBad(java.nio.file.Path):void, 3, PULSE_RESOURCE_LEAK, no_bucket, ERROR, [allocation part of the trace starts here,allocated by constructor `java.io.BufferedReader()` here,resource becomes unreachable here]
codetoanalyze/java/pulse/FilesLeaks.java, codetoanalyze.java.infer.FilesLeaks.newBufferedWriterNotClosedAfterWriteBad(java.nio.file.Path):void, 2, PULSE_RESOURCE_LEAK, no_bucket, ERROR, [allocation part of the trace starts here,allocated by constructor `java.io.BufferedWriter()` here,resource becomes unreachable here]
codetoanalyze/java/pulse/FilesLeaks.java, codetoanalyze.java.infer.FilesLeaks.newBufferedWriterNotClosedAfterWriteBad(java.nio.file.Path):void, 3, PULSE_RESOURCE_LEAK, no_bucket, ERROR, [allocation part of the trace starts here,allocated by constructor `java.io.BufferedWriter()` here,resource becomes unreachable here]
codetoanalyze/java/pulse/FilesLeaks.java, codetoanalyze.java.infer.FilesLeaks.newByteChannelNotClosedAfterReadBad(java.nio.file.Path):void, 3, PULSE_RESOURCE_LEAK, no_bucket, ERROR, [allocation part of the trace starts here,allocated by constructor `java.nio.channels.SeekableByteChannel()` here,resource becomes unreachable here]
codetoanalyze/java/pulse/FilesLeaks.java, codetoanalyze.java.infer.FilesLeaks.newByteChannelNotClosedAfterReadBad(java.nio.file.Path):void, 4, PULSE_RESOURCE_LEAK, no_bucket, ERROR, [allocation part of the trace starts here,allocated by constructor `java.nio.channels.SeekableByteChannel()` here,resource becomes unreachable here]
codetoanalyze/java/pulse/FilesLeaks.java, codetoanalyze.java.infer.FilesLeaks.fileChannelOpenNotClosedAfterWriteBad(java.nio.file.Path):void, 3, PULSE_RESOURCE_LEAK, no_bucket, ERROR, [allocation part of the trace starts here,allocated by constructor `java.nio.channels.FileChannel()` here,resource becomes unreachable here]
codetoanalyze/java/pulse/FilesLeaks.java, codetoanalyze.java.infer.FilesLeaks.fileChannelOpenNotClosedAfterWriteBad(java.nio.file.Path):void, 4, PULSE_RESOURCE_LEAK, no_bucket, ERROR, [allocation part of the trace starts here,allocated by constructor `java.nio.channels.FileChannel()` here,resource becomes unreachable here]
codetoanalyze/java/pulse/FilterInputStreamLeaks.java, codetoanalyze.java.infer.FilterInputStreamLeaks.bufferedInputStreamNotClosedAfterReadBad():void, 9, PULSE_RESOURCE_LEAK, no_bucket, ERROR, [allocation part of the trace starts here,allocated by constructor `java.io.BufferedInputStream()` here,resource becomes unreachable here]
codetoanalyze/java/pulse/FilterInputStreamLeaks.java, codetoanalyze.java.infer.FilterInputStreamLeaks.checkedInputStreamNotClosedAfterReadBad():void, 9, PULSE_RESOURCE_LEAK, no_bucket, ERROR, [allocation part of the trace starts here,allocated by constructor `java.util.zip.CheckedInputStream()` here,resource becomes unreachable here]
codetoanalyze/java/pulse/FilterInputStreamLeaks.java, codetoanalyze.java.infer.FilterInputStreamLeaks.cipherInputStreamNotClosedAfterSkipBad():void, 9, PULSE_RESOURCE_LEAK, no_bucket, ERROR, [allocation part of the trace starts here,allocated by constructor `javax.crypto.CipherInputStream()` here,resource becomes unreachable here]
Expand Down
Loading