package Examples; /* This class exposes a weakness in the current coverage sensor: the handling of loops. * There is only one path through the class, but each time the loop is entered * Sensor.tick is called again. * * E.g. if the loop is executed 25 times, the observed path will have 78 nodes: * 0 * 4 1 3 4 1 2 } * ... } pattern repeats 12 times total: 12x6 = 72 nodes * 4 1 3 4 1 2 } * 4 1 3 * 4 5 * * If the loop is repeated even 50 times, the Sensor will crash because * the heap grows too large. * * This presents a real problem if an instrumented class where to have a inner loop that executed 50+ times. * * A potential - but unsatisfying - solution would be to sense whether loops are entered * and then to not sense within the loop themselves. * This example also shows that multiple paths are possible within a loop, so such a solution would * be inadequate. * * To solve this we need to store observed edges in a set, not a list. * * Or: we need to observe prime paths, not whole paths. * * PROBLEM solved with TrieSensor * */ public class ExponentialLoop { public int loop() { int node = 0; int count = 0; while(count++<25) { if(count % 2 == 0) node = 1; else node = 2; } return node; } }