Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ public class ByteBufTest {

public static final int TEST_BUFFER_SIZE = 128;

// private ByteBuffer mDirectBuffer;
private ByteBuffer mDirectBuffer;

public ByteBufTest() {
// FIX (from accepted answer): mDirectBuffer = ByteBuffer.wrap(new byte[TEST_BUFFER_SIZE]);
// or guard with: if (mDirectBuffer.hasArray()) { ... }
ByteBuffer mDirectBuffer = ByteBuffer.wrap(new byte[TEST_BUFFER_SIZE]);
// VIOLATION: a direct buffer is not array-backed -> array() throws
// UnsupportedOperationException.
mDirectBuffer = ByteBuffer.wrap(new byte[TEST_BUFFER_SIZE]);
// wrap returns an array-backed buffer, so the field retains the state required by array()
byte[] buf = mDirectBuffer.array();
buf[1] = 100;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ public class ByteBufTest {

public static final int TEST_BUFFER_SIZE = 128;

// private ByteBuffer mDirectBuffer;
private ByteBuffer mDirectBuffer;

public ByteBufTest() {
// FIX (from accepted answer): mDirectBuffer = ByteBuffer.wrap(new byte[TEST_BUFFER_SIZE]);
// or guard with: if (mDirectBuffer.hasArray()) { ... }
ByteBuffer mDirectBuffer = ByteBuffer.allocateDirect(TEST_BUFFER_SIZE);
mDirectBuffer = ByteBuffer.allocateDirect(TEST_BUFFER_SIZE);
// VIOLATION: a direct buffer is not array-backed -> array() throws
// UnsupportedOperationException.
byte[] buf = mDirectBuffer.array(); // State Refinement Error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,19 @@ public static String prepareInvocationTarget(TypeChecker tc, CtElement target2,
// v--------- field read
// means invocation is in a form of `t.method(args)`
String name = v.getVariable().getSimpleName();
if (target2 instanceof CtFieldRead<?> fieldRead && fieldRead.getTarget() instanceof CtThisAccess<?>) {
String fieldName = String.format(Formats.THIS, name);
if (tc.getContext().hasVariable(fieldName))
name = fieldName;
}
Optional<VariableInstance> invocationCallee = tc.getContext().getLastVariableInstance(name);
if (invocationCallee.isPresent()) {
invocation.putMetadata(Keys.TARGET, invocationCallee.get());
} else if (target2.getMetadata(Keys.TARGET) == null) {
RefinedVariable var = tc.getContext().getVariableByName(name);
if (var == null)
return name;

String nName = String.format(Formats.INSTANCE, name, tc.getContext().getCounter());
RefinedVariable rv = tc.getContext().addInstanceToContext(nName, var.getType(),
var.getRefinement().substituteVariable(name, nName), target2);
Expand Down
Loading