
275 Cal.App.2d 483 (1969)
In re ANDREW CARLOS VALENZUELA, a Person Coming Under the Juvenile Court Law. WARREN E. THORNTON, as Probation Officer, etc., Plaintiff and Respondent,
v.
ANDREW CARLOS VALENZUELA, Defendant and Appellant.
Civ. No. 12158. 
California Court of Appeals. Third Dist.  
Aug. 6, 1969.
 Kenneth M. Wells, Public Defender, and Michael S. Sands, Assistant Public Defender, for Defendant and Appellant in Civ. No. 12158 and Petitioner in Crim. No. 5183.
 Thomas C. Lynch, Attorney General, Doris H. Maier, Assistant Attorney General, jack R. Winkler, Arnold O. Overoye and Robert A. Fowler, Deputy Attorneys General, for Plaintiff and Respondent in Civ. No. 12158 and Respondent in Crim. No. 5183.
 PIERCE, P. J.
 The two matters captioned above involve the same person, the same facts and correlated issues. We have ordered them consolidated for argument and for opinion. The first matter is an appeal from a judgment of the juvenile court which contains an order extending the jurisdiction of the California Youth Authority over Valenzuela for a period of two years under the provisions of Welfare and Institutions Code section 1800.  [fn. 1] The second matter is an attack by way of habeas corpus upon the Authority's continuing jurisdiction over Valenzuela.
 Valenzuela, who is now 24 years old, is confined at Deuel Vocational Institution. He has been under the supervision of the Authority since 1960. Neither on the original nor on any subsequent proceeding has Valenzuela had a jury trial. Under none of the statutory proceedings covering the custodial restraints placed upon him was the right of a jury trial afforded. Amendments and additions to the Welfare and Institutions Code in 1963 (hereinafter to be discussed) could--if applied to Valenzuela and given maximum effect--result in his incarceration for the rest of his life. [1a] The principal contention is that the statutory provisions mentioned are, as applied to Valenzuela, ex post facto and therefore unconstitutional. The contention is valid.
 On June 29, 1960, Valenzuela was committed to the Authority as a ward of the Juvenile Court of Sacramento County. *485 The commitment arose out of charges that the minor had sexually molested an 11-year-old girl. Originally the commitment would have expired in August 1966. Three paroles were granted; all were revoked for violation of conditions of parole. All violations excepting one were similar, or at least related, in their nature--sexual molestation of 11-year-old girls. (One involved the solicitation of 11-year-old girls to pose for indecent photographs. The unrelated parole violation was that Valenzuela had run away from a foster home.)
 At the time of the original commitment section 1769 as amended in 1941 (Stats. 1941, ch. 937) covered the maximum jurisdiction of the Authority over Valenzuela. That section then provided: "Every person committed to the Authority by a juvenile court shall be discharged upon the expiration of a two-year period of control or when the person reaches his twenty-first birthday, whichever occurs later."  [fn. 2]
 Sections 1769, 1770 and 1771 were amended in 1963. (Stats. 1963, ch. 1693.) In each section after the provision fixing maximum jurisdiction, there was added: "unless an order for further detention has been made by the committing court pursuant to Article 6 (commencing with Section 1800)." Sections 1800-1803 were added.
 Section 1800 provides that whenever the Youth Authority determines that discharge of a person from control of the Authority under section 1769 is physically dangerous to the public because of the person's mental or physical deficiency, disorder, or abnormality, the Authority may request the committing court to order that the period of detention be extended for two years.
 Certain procedural safeguards are provided for the person, including the right to counsel ( 1801), but no provision is made for the issues of fact to be determined by a jury.
 This procedure can be repeated as often as necessary, thus meaning that a person could be detained in custody for the rest of his life. In addition, any person over 21 can be transferred from the custody of the Youth Authority to the Director of Corrections for placement in a state prison. ( 1802.) *486
 Section 1803 provides that such order "is appealable by the person whose liberty is involved in the same manner as a judgment in a criminal case."
 By two proceedings, one in July 1966 and the other completed in August 1968, the Authority acting pursuant to sections 1769 and 1800-1803 sought and obtained successive orders from the Sacramento Juvenile Court extending Valenzuela's detention. The first order extended detention to August 28, 1968, the latter to August 27, 1970. (Valenzuela was represented by assigned counsel in both proceedings; the second proceeding was contested.) It is from the second of the two orders that this appeal has been taken.
 [2] An ex post facto law is one that (1) makes an act, or omission, occurring before the passing of the law, and innocent before the passing of the law, criminal and subject to punishment, or (2) aggravates a crime or makes it greater than it was when committed, or (3) increases the punishment, or otherwise changes it to the disadvantage of the defendant, or (4) alters the legal rules of evidence by requiring less or different testimony than the law required at the time of the commission of the offense to convict the offender. (People v. Bradford (1969) 70 Cal.2d 333, 343 [74 Cal.Rptr. 726, 450 P.2d 46].) Ex post facto laws are prohibited both by the federal Constitution (art. I,  9, cl. 3) and the California Constitution (art. I,  16). [3] The prohibition against ex post facto laws applies only to punitive and criminal matters. (Galvan v. Press (1954) 347 U.S. 522, 531 [98 L.Ed. 911, 922, 74 S.Ct. 737]; Smith v. Smith (1955) 131 Cal.App.2d 764, 768 [281 P.2d 274].)
 [1b] The Attorney General argues that the procedures under sections 1765-1771 and 1800-1803 are civil rather than criminal, rehabilitative rather than punitive. It is also contended that the detention suffered by petitioner is not imposed for the antecedent act which resulted in commitment but rather it is based upon the fact that his release would present a danger to the public.
 The original proceedings started with a commitment, not a conviction. There was no jury trial and no right to one. Valenzuela had no attorney during those proceedings and, at the time, no law specified a right to one. (We will touch upon this below.)proceedings are now at a stage where Valenzuela, no longer a minor, finds himself presently incarcerated in a penal institution. He has been so confined for a number of years. The name "vocational institution" has optimistic connotations *487 but Deuel receives many young men who require and receive the security afforded by a maximum security institution. When its facilities are deemed inadequate for that purpose transfer may be made to a state prison. The laws challenged here provide for successive proceedings indefinite in number. Under these, as we have noted, Valenzuela may remain incarcerated for life. We cannot regard this legislation viewed as a system, as being civil rather than criminal. It is penal in nature and effect.
 We do not doubt that the procedural steps outlined are aimed at rehabilitation. Our entire penal system has that as a purpose. But an overriding policy of all these laws is the protection of society against persons "physically dangerous to the public" because of their "mental or physical deficiency, disorder, or abnormality." ( 1800.)
 We do not accept the contention that the challenged statutes as applied here are not ex post facto because Valenzuela is now confined not for the antecedent offense but because of subsequent offenses. The initial offense was the original and indispensable link in the chain of circumstances from which all other steps followed. Were it not for the original juvenile court proceeding the authorities in 1966 would have had to start either with criminal proceedings in the event a new offense was committed, followed by further proceedings for commitment under the provisions of the mentally disordered sex offender law ( 5500 et seq., repealed Stats. 1967, ch. 1667,  36.5, p. 4107, operative July 1, 1969) or, prior to the commission of a new offense, with proceedings for Valenzuela's commitment as a mentally ill person ( 5500 et seq., effective July 1, 1969.)  [fn. 3] Under either course, a jury trial would have been available. ( 5512.5, 5572.)
 A further contention has been made on behalf of petitioner. It is that Valenzuela was not represented by an attorney at the original proceedings, was not offered one, and did not waive representation by an attorney. Re Gault (1967) 387 U.S. 1, 41 [18 L.Ed.2d 527, 554, 87 S.Ct. 1428], asserts a rule that in juvenile court proceedings which may result in incarceration the minor is entitled to be represented by counsel and, if indigent, to have counsel appointed to represent him--unless there is an intelligent and meaningful waiver.
 Re Gault is the most comprehensive decision of any court *488 on the rights of juveniles appearing before juvenile courts. It sweeps aside fallacies built around the parens patriae theory. It views realistically the plight of such youths and points out why they need--even more, perhaps, than the adult--bill of rights' protections, why it is tongue-in-cheek casuistry to label proceedings affecting them as "civil" when they have totally criminal consequences.
 Gault does not determine, and so far as we have been informed, no subsequent United States Supreme Court decision or decision in California has determined whether or to what extent, if any, the Gault rule is retroactive. (Cf. Re Whittington (1968) 391 U.S. 341 [20 L.Ed.2d 625, 88 S.Ct. 1507].)petitioner argues that we should determine that the rule is retroactive and, therefore, irrespective of the application of the ex post facto constitutional proscription, Valenzuela's present detention is illegal. Since we hold that the detention is invalid because it is under the ex post facto interdiction we do not reach the second question.
 Although constitutional demands require termination of Valenzuela's imprisonment, his history gives reason to suspect that he is an emotionally disturbed, compulsive sex offender, hence a danger to society. A well- conceived body of laws would permit an inquiry with a view to his hospitalization and restraint under civil commitment before--not after--he commits a new sex crime. Such a statutory arrangement is constitutionally permissible when accompanied by appropriate safeguards. (Baxstrom v. Herold, 383 U.S. 107 [15 L.Ed.2d 620, 86 S.Ct. 760].) Apparently California's only statutory medium for accomplishing his involuntary civil commitment is the Lanterman-Petris-Short Act. ( 5000 et seq.) That act appears to sanction extended involuntary detention only after the patient manifests assaultive behavior. ( 5300.) Thus, the present California legislation reveals no discernible, rational solution to the social problem posed by this subject's unconditional release.
 The order appealed from is reversed. The writ is granted.
 Friedman, J., and Janes, J., concurred.
NOTES
[fn. 1]  1. Unless otherwise noted all code section references in this opinion will be to the Welfare and Institutions Code.
[fn. 2]  2. That section was one of five sections (1765-1771) relevant to the duration of supervision, control, and maximum jurisdiction by and of the Authority. Maximum jurisdiction varied dependent upon whether the offense was a misdemeanor or a felony and whether there had been a conviction. Since no conviction had preceded this minor's commitment 1769 was the effective section covering maximum jurisdiction and August 27, 1966, Valenzuela's 21st birthday, was the termination date of the jurisdiction of the Authority.
[fn. 3]  3. Commencing July 1, 1969, commitment proceedings are to be controlled by the provisions of the Lanterman-Petris-Short Act effective July 1, 1969.
