package tracematches; import java.util.*; public class HasNextElem { static aspect HashNextElemCheck{ tracematch(Enumeration e) { sym hasNext before : call(boolean Enumeration.hasMoreElements()) && target(e); sym next before : call(Object Enumeration.nextElement()) && target(e); next next { if(System.getProperty("TMTEST_ACTIVE")!=null) { throw new RuntimeException("Should call 'boolean Enumeration.hasMoreElements()'"); } } } } public static void main(String[] args) { //unsafe Vector c = new Vector(); c.add(""); c.add(""); Enumeration e = c.elements(); System.out.println("n1"); e.nextElement(); e.hasMoreElements(); System.out.println("n2"); e.nextElement(); System.out.println("n3"); e.nextElement(); //safe but not detected as such (needs must-point-to info) Vector c2 = new Vector(); Enumeration e2 = c2.elements(); while(e2.hasMoreElements()) { e2.nextElement(); } } }