Details about the known misuse from the MUBench dataset.
| Description: | Misses to call ByteBuffer.flip() between writing to and reading from the buffer (or vice versa). There''s many ways to read/write buffer, some of which fail if flip() is missing, while others just do nothing. StackOverflow: http://stackoverflow.com/questions/10166011/how-to-use-java-nio-channels-filechannel-to-write-a-byte-to-a-file-basics/10166055
|
| Fix Description: |
Add a call to ByteBuffer.flip()
|
| Violation Types: |
|
| In File: | ByteBufferFlip.java |
| In Method: | misuse(ByteBuffer, byte[]) |
| Code with Misuse: |
class ByteBufferFlip {
public void misuse(ByteBuffer buf, byte[] content) throws IOException {
buf.put(content);
buf.get();
}
}
|
| Code with Pattern(s): |
public class FlipBuffer {
public void pattern(byte[] content) throws IOException {
ByteBuffer buffer = ByteBuffer.allocate(content.length);
buffer.put(content);
buffer.flip(); // <-- required for subsequent reading
buffer.get();
}
}
|