Boone v Ontario (Community Safety and Correctional Services) (Ont CA, 2014)
In this useful case the court canvassed the law applicable to habeas corpus, here in an application by a sexually-active prisoner with AIDS to be released from solitary confinement:
 To be successful, an applicant for habeas corpus must show (a) a deprivation of liberty and (b) that the deprivation of liberty was unlawful: May v. Ferndale Institution, 2005 SCC 82 (CanLII),  3 S.C.R. 809, at para. 74; and Mission Institute v. Khela, 2014 SCC 24 (CanLII), 2014 SCC 24, at para. 30. Between these points, there are other considerations in play, however.
 First, once a deprivation of liberty has been shown, and the applicant has raised a legitimate ground on which to question its validity, the onus shifts to the Crown to show that the deprivation was lawful. Secondly, where a deprivation of liberty has occurred, and a legitimate ground to question its validity has been raised, the hearing judge must proceed to a hearing; there is no discretion to do otherwise. Finally, the hearing judge retains a “residual discretion” at this second stage of the proceedings to decide, after reviewing the record, whether to discharge the applicant: see Khela, at paras. 30 and 78.
 These considerations bear on the appellant’s contention that, once the application judge found breaches of procedural fairness, he had no discretion to refuse to grant the writ of habeas corpus. The appellant is mistaken in his characterization of the writ in this way, in my view.
 It is true that habeas corpus is a remedy that issues as of right (ex debito justitiae) once the unlawful nature of the detention is established. It cannot be denied because another, equally effective remedy – such as judicial review – exists. That was the issue debated in May and Khela. As LeBel J. affirmed in Khela, however, the non-discretionary nature of the writ relates to whether the applicant has raised a legitimate basis for questioning the legality of the detention, not to the ultimate determination of whether, on the whole of the record, the unlawful nature of the detention is established. There remains a residual discretion in this regard. At paras. 77 and 78, he said:
First, the traditional onuses associated with the writ will remain unchanged. Once the inmate has demonstrated that there was a deprivation of liberty and casts doubt on the reasonableness of the deprivation, the onus shifts to the respondent authorities to prove that the transfer was reasonable in light of all the circumstances. Where there has been a denial of the right to a fair hearing, the administrative decision will always be unlawful. However, not all procedural breaches will necessarily result in procedural unfairness and the denial of the right to a fair hearing: see Khela, at para. 90; Canadian College of Business and Computers Inc. v. Ontario (Private Career Colleges Act, Superintendent), 2010 ONCA 856 (CanLII), 2010 ONCA 856, at paras. 65-67; and Uniboard Surfaces Inc. v. Kronotex Fussboden GmbH and Co. KG (F.C.A.), 2006 FCA 398 (CanLII), 2006 FCA 398,  4 F.C.R. 101, at para. 24.
Second, the writ remains non-discretionary as far as the decision to review the case is concerned. If the applicant raises a legitimate doubt as to the reasonableness of the detention, the provincial superior court judge is required to examine the substance of the decision and determine whether the evidence presented by the detaining authorities is reliable and supports their decision. Unlike the Federal Court in the context of an application for judicial review, a provincial superior court hearing a habeas corpus application has no inherent discretion to refuse to review the case (see Farbey, Sharpe and Atrill, at pp. 52-56). However, a residual discretion will come into play at the second stage of the habeas corpus proceeding, at which the judge, after reviewing the record, must decide whether to discharge the applicant.