
68 Cal.2d 854 (1968)
In re GUY EARL BEVILL on Habeas Corpus.
Crim. No. 11009. 
Supreme Court of California. In Bank.  
July 8, 1968.
 Guy Earl Bevill, in pro. per., Gerald Z. Marer, under appointment by the Supreme Court, and Long & Levit for Petitioner.
 Thomas C. Lynch, Attorney General, Albert W. Harris, Jr., Assistant Attorney General, Edward P. O'Brien and Derald E. Granberg, Deputy Attorneys General, for Respondent.
 PETERS, J.
 Petitioner Guy Earl Bevill, confined in the California State Prison at San Quentin for an indeterminate period as a mentally disordered sex offender, filed in propria persona a petition for habeas corpus attacking the validity of his imprisonment on the ground that he was convicted under an unconstitutional statute. We issued an order to show cause and appointed counsel. We have concluded that the writ must be granted and the prisoner ordered discharged from custody.
 On September 17, 1961, in Glendale, California, petitioner was arrested for engaging in an act of masturbation in the *857 presence of two children. He was charged with a violation of section 650 1/2 of the Penal Code,  [fn. 1] pled not guilty, and waived jury trial. The court found him guilty, adjourned the criminal proceedings without imposing sentence, and certified him to the superior court for hearing and examination to determine whether he was a mentally disordered sex offender within the meaning of former section 5500 (now 6300)  [fn. 2] of the Welfare and Institution Code.
 At a hearing on November 20, 1961, the superior court found petitioner to be a mentally disordered sex offender and ordered him sent to the Atascadero State Hospital for a period of observation not to exceed 90 days. On February 7, 1962, the superintendent of the hospital advised the court that petitioner was a mentally disordered sex offender, could benefit from treatment in a state hospital, and should be committed to the Department of Mental Hygiene for placement in Atascadero State Hospital for an indeterminate period. By ex parte order of February 13, the superior court committed petitioner to the Department of Mental Hygiene.petitioner neither moved for a new trial nor appealed from the order of commitment.
 After two years, petitioner was returned to the committing court. The superintendent of the hospital reported that petitioner would not benefit from further treatment but remained a danger to society, and recommended that he be recommitted to the Department of Mental Hygiene and sent to the California Institution for Men at Chino for an indeterminate period. Petitioner did not appeal from the order of recommitment. On June 10, 1966, he was transferred to the state prison at San Quentin.
 [1a] The previously unexplored question presented by this petition is whether a person confined as a mentally disordered sex offender may challenge the validity of his criminal *858 conviction on habeas corpus. [2] Conviction of a crime is prerequisite to commitment as a mentally disordered sex offender. (In re Stoneham, 232 Cal.App.2d 337, 340-341 [42 Cal.Rptr. 741].) But proceedings for commitment are civil in nature and are collateral to the criminal proceedings. (Gross v. Superior Court, 42 Cal.2d 816, 820 [270 P.2d 1025].) [3] A person committed as a mentally disordered sex offender is not confined for the criminal offense but because of his status as a mentally disordered sex offender. (People v. Rancier, 240 Cal.App.2d 579, 584- 585 [49 Cal.Rptr. 876]; In re Keddy, 105 Cal.App.2d 215, 217 [233 P.2d 159].) The confinement is pursuant to a law the primary purpose of which is protection of society. (People v. McCracken, 39 Cal.2d 336, 346 [246 P.2d 913]; People v. Levy, 151 Cal.App.2d 460, 468 [311 P.2d 897].) [4] While a person is under such commitment, the criminal case against him is suspended. When the proceedings relating to commitment as a mentally disordered sex offender have run their course, the criminal case may be resumed and sentence imposed. (People v. De La Roi, 185 Cal.App.2d 469, 472 [8 Cal.Rptr. 260].) [5] Habeas corpus is appropriate to challenge the validity of a person's commitment or continued confinement as a mentally disordered sex offender. (People v. Harvath, 251 Cal.App.2d 780, 781 [60 Cal.Rptr. 15]; In re Stoneham, supra, 232 Cal.App.2d 337.) [6] And appeal will lie from an order denying a new trial despite the fact that neither judgment nor sentence have been entered because of the pendency of commitment proceedings. (Thurmond v. Superior Court, 49 Cal.2d 17, 23 [314 P.2d 6]; People v. Moody, 216 Cal.App.2d 250, 251 [30 Cal.Rptr. 785].)
 In brief, because petitioner's confinement is pursuant to an independent judicial determination had in civil proceedings collateral to his criminal conviction, there arises the question whether issues relating to his conviction are presently cognizable on habeas corpus or whether they must await petitioner's return to the criminal court and his sentencing on the conviction. [1b] If, as we have concluded, the validity of a commitment as a mentally disordered sex offender is affected by the validity of the prerequisite criminal conviction, then issues pertaining to the conviction insofar as they test the legality of present confinement are clearly cognizable on habeas corpus. But even if the conviction and subsequent commitment were of discrete efficacy, the conviction could be *859 attacked on habeas corpus although a release from custody could not be thereby accomplished.  [fn. 3]
 The question whether a person committed as a mentally disordered sex offender is entitled to release because of the invalidity of his conviction has been answered in the negative by one federal court. In Wilson v. Blabon (9th Cir. 1967) 370 F.2d 997, the petitioner sought habeas corpus to obtain discharge from his commitment on the ground that his misdemeanor conviction was invalid. The court held that a constitutionally invalid conviction is a sufficient conviction for purposes of commitment, relying on Thurmond v. Superior Court, supra, 49 Cal.2d 17, and In re Morehead, 107 Cal.App.2d 346 [237 P.2d 335]. Neither case dealt with whether the commitment would be invalidated if the conviction were invalidated. Accordingly, we decline to follow Wilson.
 In a number of states sexual psychopathy proceedings may be instituted against a person who has been merely charged with a crime.  [fn. 4] This situation pertained in California prior to 1949 when section 5501 (6302) of the Welfare and Institutions Code provided that proceedings for commitment could be commenced "when any person is charged with a crime, either before or after adjudication of the charge." (Stats. 1939, ch. 447,  1, p. 1783.) In 1949 the statute was recast to allow commitment "after adjudication of the charge" (Stats. 1949, ch. 1325,  1, p. 2311), in 1950 to allow commitment *860 "when a person is convicted of a criminal offense" (Stats. First Ex. Sess. 1950, ch. 7,  1, p. 439), and in 1951 to allow commitment "when a person is convicted of any criminal offense" (Stats. 1951, ch. 1759,  1, p. 4186). The Legislature, by requiring a conviction prior to commitment, intended to create a more solid safeguard to liberty. An invalid conviction does not fulfill that legislative goal.
 [7] The mentally disordered sex offender is not legally insane (In re Keddy, supra, 105 Cal.App.2d 215, 218); he is not even necessarily a "sex offender" because the crime of which he is convicted need not be a sex offense (Wel. & Inst. Code,  5501 (6302)); he is "any person who by reason of mental defect, disease, or disorder, is predisposed to the commission of sexual offenses to such a degree that he is dangerous to the health and safety of others." (Welf. & Inst. Code,  5500 (6300) (italics added).) Many individuals who satisfy the definition of "mentally disordered sex offender" would be subject to civil commitment to a mental institution under other provisions of the law,  [fn. 5] but it is not clear that all would be. [8] The primary purpose of quarantining mentally disordered sex offenders is protection of the public, and the Legislature has ordained that that group of persons from whom the public must be protected is to be identified by, inter alia, the fact of conviction for the perpetration of a criminal act. (See People v. Levy, supra, 151 Cal.App.2d 460, 463-467.) The mentally disordered sex offender faces the imposition of substantial legal disabilities;  [fn. 6] unlike other mental patients, he *861 faces the imposition of special criminal sanctions other than for his conviction;  [fn. 7] and should the rehabilitative ideal fail of fruition, he faces life imprisonment in a penal institution. Imposition of these conditions on the innocent as well as the guilty does not serve to protect the public. Important in this regard is the fact that persons sentenced to death and persons ineligible for probation are exempted from the operation of the statute. (Welf. & Inst. Code,  5500.5 (6301).) If the convictions are valid society will be protected under the sentences imposed; if the convictions are invalid the statute provides no basis to commit even those accused of the most socially dangerous conduct. (Cf. People v. McCracken, supra, 39 Cal.2d 336, 346.)
 [9] The structure of the statute itself manifests the integral and continuing relation foreseen to exist between commitment and conviction. The criminal proceedings are "adjourned" when commitment proceedings commence. (Welf. & Inst. Code,  5501 (6302).) If the subject is immediately determined not to be a mentally disordered sex offender, criminal proceedings are resumed. (Welf. & Inst. Code,  5511.7 (6315).) If the subject is tentatively determined to be a mentally disordered sex offender, he is committed for 90 days and then returned to court. Upon his return, he is either finally committed or sentenced. (Welf. & Inst. Code,  5512 (6316).) If he is committed, the committing court may require periodic reports on his status (Welf. & Inst. Code,  5512.3 (6317)) and may have the subject returned for examination at six-month intervals (Welf. & Inst. Code,  5519 (6327).) If an individual is eventually found not amenable to further treatment and not a danger to others, he is returned to court for sentencing. (Welf. & Inst. Code,  5517 (6325).) Time spent under an indeterminate commitment "shall be credited in fixing ... term of sentence." (Welf. & Inst. Code,  5517 (6325).) If a person is found not amenable to further treatment and a continuing danger to others, he may be either recommitted or sentenced. (Welf. & Inst. Code,  5518 (6326).)
 These procedures exist in a context in which the individual is allowed to take an immediate appeal from an order denying a new trial. The order may be reversed. If reversed, the *862 prisoner may not be retried; or he may be retried and acquitted; in either event, jurisdiction to continue the criminal proceedings would be lost, and the entire statutory edifice would become a shambles of meaningless alternatives.
 Legislative history, the raison d'etre of the conviction requirement, and the structure and fabric of the statute all attest that a valid commitment must be based upon a valid conviction.
 Petitioner contends that he is unlawfully confined because section 650 1/2 of the Penal Code is unconstitutional. In re Davis, 242 Cal.App.2d 645 [51 Cal.Rptr. 702], held that portion of section 650 1/2 prohibiting acts which openly outrage public decency unconstitutional and void for vagueness. [10] Habeas corpus is a proper remedy to review a conviction under an unconstitutional statute (In re Newbern, 53 Cal.2d 786, 792 [3 Cal.Rptr. 364, 350 P.2d 116]; In re Porterfield, 28 Cal.2d 91, 99 [168 P.2d 706, 167 A.L.R. 675]), and when a conviction is so attacked, the prisoner need not have exhausted his remedy by appeal (In re Dixon, 41 Cal.2d 756, 762 [264 P.2d 513]; In re Bell, 19 Cal.2d 488, 493 [122 P.2d 22]).
 [11] Petitioner was found guilty of a charge under section 650 1/2 which recited, paraphrasing the statute, that he "did willfully, wrongfully and unlawfully commit an act which openly outraged public decency and seriously disturbed and endangered the public peace." Even if a part of the statute is constitutional (a point we do not pass upon) petitioner could not be convicted under the assumed valid portion. This is so because section 650 1/2 applies only to acts "for which no other punishment is expressly prescribed by this code."petitioner's acts were expressly described and interdicted by Penal Code section 314, subdivision 1, which pertains to indecent exposure of "person, or the private parts thereof, in any public place, ..." (See People v. Merriam, 66 Cal.2d 390 [58 Cal.Rptr. 1, 426 P.2d 161]; People v. Kerry, 249 Cal.App.2d 246 [57 Cal.Rptr. 289]; see also, Pen. Code,  647, 647a; People v. McNair, 130 Cal.App.2d 696 [279 P.2d 800].) Conviction under section 650 1/2 was therefore plainly erroneous.  [fn. 8] (People v. Proctor, 46 Cal.2d 481 *863 [296 P.2d 821]; People v. Hunter, 208 Cal.App.2d 633 [25 Cal.Rptr. 492].) [12] A defendant is entitled to habeas corpus if it appears that the statute under which he was convicted did not prohibit his conduct. (In re Zerbe, 60 Cal.2d 666, 668 [36 Cal.Rptr. 286, 388 P.2d 182, 10 A.L.R.2d 840]; In re Allen, 59 Cal.2d 5, 6 [27 Cal.Rptr. 168, 377 P.2d 280, 97 A.L.R.2d 1415].) Because such a conviction is in excess of a court's jurisdiction (In re Zerbe, supra, 60 Cal.2d 666, 667-668), a defendant need not have exhausted his remedies by appeal (see Witkin, Cal. Criminal Procedure (1963)  797 (c), p. 770).  [fn. 9]
 Petitioner's conviction is not valid because the statute under which he was convicted did not apply to his conduct. Since the efficacy of his commitment was undermined by the deficiency of his conviction, a writ of habeas corpus must be granted ordering his discharge. It is unnecessary to state, of course, that nothing we decide here precludes the initiation of civil commitment proceedings under any appropriate statute.
 The writ is granted and petitioner is discharged from custody.
 Traynor, C. J., Tobriner, J., Mosk, J., Burke, J., and Sullivan, J., concurred.
 McCOMB, J.
 I dissent. I would deny the writ.
NOTES
[fn. 1]  1. Section 650 1/2 provides in pertinent part: "A person who wilfully and wrongfully commits any act ... which seriously disturbs or endangers the public peace or health, or which openly outrages public decency ... for which no other punishment is expressly prescribed by this code, is guilty of a misdemeanor."
[fn. 2]  2. The article defining and describing the disposition of mentally disordered sex offenders, formerly codified as Welfare and Institutions Code sections 5500-5522, has been recodified as Welfare and Institutions Code sections 6300-6330 operative the sixty-first day after final adjournment of the 1968 Regular Session of the Legislature. Unless otherwise indicated, the section number appearing first in the text will conform with the old classification. The parenthetical section number will correspond to the new classification.
[fn. 3]  3. The suggestion that a prisoner must endure his invalid conviction until he is actually confined under it proposes an application of the doctrine of "prematurity."prematurity, an aspect of the larger common law rules pertaining to the custody requisite for relief in habeas corpus, is in issue when a petition for habeas corpus is questioned as too early. The leading case on the doctrine was McNally v. Hill, 293 U.S. 131, 138 [79 L.Ed. 238, 242, 55 S.Ct. 24], which held that habeas corpus would not lie to attack future consecutive sentences. McNally was overruled in Peyton v. Rowe (1968) 391 U.S. 54 [20 L.Ed.2d 426, 88 S.Ct. 1549]. This court declined to follow the McNally rationale as early as In re Chapman, 43 Cal.2d 385, 387 [273 P.2d 817]. The potential of the prematurity doctrine for waste, delay, and injustice was ably and perceptively explored in Commonwealth v. Myers (1965) 419 Pa. 1 [213 A.2d 613, 620-624]. (See generally, Note (1966) 65 Mich.L.Rev. 172.)
[fn. 4]  4. See, e.g., Ala. Code tit. 15,  436; Fla. Stat. Ann.,  917.12; Ill. Ann. Stat., ch. 38,  105-3; Ind. Ann. Stat.,  9-3403; Mich. Stat. Ann.,  28.967(3); Mo. Ann. Stat.,  202.710; N.H. Rev. Stat. Ann.,  173:3; Wash. Rev. Code Ann.,  71.06.020. See generally, Department of Mental Hygiene, California Sexual Deviation Research (Final Report, March 1954) pp. 15-58; Lindman and McIntyre, The Mentally Disabled and the Law (1961) pp. 298-329; Note, The Plight of the Sexual Psychopath: A Legislative Blunder and Judicial Acquiescence (1966) 41 Notre Dame Law., 527, 528-538; Note 24 A.L.R.2d 350.
[fn. 5]  5. For typical provisions under the 1967 Mental Health (Lanterman-Petris-Short) Act, see, e.g., Welfare and Institutions Code, section 5150 (dangerous or gravely disabled persons), section 6250 (persons subject to judicial commitment), section 6450 (mentally abnormal sex offenders), and section 6500 (mentally retarded persons). See generally, Subcommittee on Mental Health Services, Assembly Interim Committee on Ways and Means, The Dilemma of Mental Commitments in California (1966) pp. 6-180. For other studies of involuntary mental commitment, see Lindman and McIntyre, The Mentally Disabled and the Law (1961) pp. 15-106; Ross, Commitment of the Mentally Ill:problems of Law and Policy (1959) 57 Mich.L.Rev. 945. See also, Morse, The Aberrational Man: A Collection of Medical and Legal Treatments of the Abnormal Mind (1967) 42 Tul.L.Rev. 67.
[fn. 6]  6. The disabilities which formerly followed mental commitment were, in the aggregate, potentially more extensive than those incident to conviction for a felony. (See Subcommittee on Mental Health Services, Assembly Interim Committee on Ways and Means, The Dilemma of Mental Commitments in California (1966) Appendix V, pp. 188-194.) The number of disabilities has been drastically reduced by the 1967 Mental Health Act. (See Stats. 1967, ch. 1667; Welf. & Inst. Code,  5005.) For the extent to which the disabilities imposed on the mentally disordered sex offender have been alleviated, see Welfare and Institutions Code section 6250.
[fn. 7]  7. See, for example, Welfare and Institutions Code section 5522 (6330), which provides that escape or attempted escape by a mentally disordered sex offender is punishable by up to five years imprisonment. (Compare Pen. Code,  4530.)
[fn. 8]  8. See Note, Appellate-Court Sua Sponte Activity: Remaking Disputes and the Rule of Non-Intervention (1967) 40 So.Cal.L.Rev. 352, 368-371. We are not unmindful that "section 650-1/2 is a section to which persons accused of sex crimes will plead guilty--or of which merciful judges will find them guilty--to avoid the stigma of registration under section 290 of the Penal Code." (In re Davis, supra, 242 Cal.App.2d 645, 666, fn. 21.)
[fn. 9]  9. We denied without opinion petitioner's prior petition for habeas corpus on March 22, 1967. Our policy is to deny a new application unless there has been a change in the facts or law (e.g., In re Chessman, 43 Cal.2d 391, 399 [274 P.2d 645]; In re Horowitz, 33 Cal.2d 534, 546 [203 P.2d 513]), but this policy is discretionary (see Witkin, Cal. Criminal Procedure (1963)  797, pp. 769-770). In view of In re Davis, supra, 242 Cal.App.2d 645, and the other circumstances of this case, we are disposed to now consider error in convicting petitioner under a statute which did not prohibit his conduct. (See In re Black, 66 Cal.2d 881, 887 [59 Cal.Rptr. 429, 428 P.2d 293].)
