Inferring Specifications to Detect Errors in Code