We choose five well-known JavaMOP properties:
Preperty | Description |
---|---|
HasNext | Program should always call hasNext() before next() on an iterator. |
SafeEnum | Collection (with an associated enumeration) should not be modified while the enumeration is in use. |
SafeSyncMap | Synchronized collection should always be accessed by a synchronized iterator, and the iterator should always be accessed in a synchronized manner. |
UnsafeIterator | When the iterator associated with a collection is accessed, the collection should not be updated. |
UnsafeMapIterator | WLike UnsafeIterator, with differences related to the creation of iterators. |
In this use case, our instrumentation cover the framework.jar which includes major Android framework implementation, the bytecode inside the target application and all dynamically loaded bytecode
Below we take the HasNext Property as example to show how we define the property to detect violation:
@Before(marker = NextInvocationMarker.class)
public static void HasNext_next(ArgumentProcessorContext pc){
Iterator receiver = (Iterator) pc.getReceiver(ArgumentProcessorMode.CALLSITE_ARGS);
HasNextRuntimeMonitor.nextEvent(receiver);
}
@After(marker = HasNextInvocationMarker.class)
public static void HasNext_hasnext(ArgumentProcessorContext pc) {
Iterator receiver = (Iterator) pc.getReceiver(ArgumentProcessorMode.CALLSITE_ARGS);
HasNextRuntimeMonitor.hasnextEvent(receiver);
}
The implementation of HasNextRuntimeMonitor is adapted from JavaMOP and can be found here.