package tracematches; import java.net.*; public class URLConn { public static aspect URLConnCheck { tracematch(URLConnection c) { sym create after returning(c): call(URLConnection URL+.openConnection()); sym connect after returning: call(* URLConnection.connect()) && target(c); sym setter before: call(* URLConnection.set*(..)) && target(c); create setter* connect setter { if(System.getProperty("TMTEST_ACTIVE")!=null) { throw new RuntimeException(c+" is already connected!"); } } } } public static void main(String[] args) throws Exception { URL url = new URL("http://www.aspectbench.org/"); //unsafe URLConnection c = url.openConnection(); c.setDoInput(false);//can go c.connect(); System.err.println("connected"); c.setDoInput(true); //safe URLConnection c1 = url.openConnection(); c1.setDoInput(true); //safe URLConnection c2 = url.openConnection(); c2.connect(); } }