Alexander L. Jacobus appeals from an order in which the trial court denied his petition for a writ of habeas corpus. Jacobus was charged with several crimes including three counts of bail jumping based solely upon his consumption of alcohol, an act prohibited by the terms of his release bonds. Pursuant to a plea agreement, he entered no contest pleas to one of these charges and several others. Jacobus argues that his habeas petition should have been granted because this conviction violates state policy set forth in § 51.45(1), Stats.,1 which prohibits the State from *787criminally charging intoxicated or alcoholic persons with consuming alcohol. We agree with Jacobus and conclude that his conviction violates state policy. Accordingly, we reverse the court's order and grant his habeas petition.
BACKGROUND
Over a three-month period in 1992, Jacobus was charged with several crimes including five counts of misdemeanor bail jumping. Three of those counts were based upon his consumption of alcohol, actions which his release bonds prohibited.2 Jacobus entered into a plea agreement with the State. He agreed to plead no contest to one count of disorderly conduct, two counts of operating a motor vehicle while intoxicated (OMVWI), and three counts of misdemeanor bail jumping. Of those three counts of misdemeanor bail jumping, only one was based solely upon his consumption of alcohol. The State agreed to dismiss the other two charges of misdemeanor bail jumping based solely upon his consumption of alcohol. The trial court imposed and stayed jail sentences, and placed Jacobus on probation.
Approximately two years later, in October 1994, Jacobus was taken into custody and his probation was revoked. That same month, he filed a petition for a writ of habeas corpus in which he argued that he should be released from incarceration because his bail jumping convictions violated state policy set forth in § 51.45(1), Stats. The trial court denied his petition. Jacobus appeals.
*788DISCUSSION
Habeas corpus tests the right of a person to his or her personal liberty. State ex rel. Dowe v. Circuit Court, 184 Wis. 2d 724, 728, 516 N.W.2d 714, 715-16 (1994). It is an equitable doctrine limited to those persons needing relief when the process or judgment upon which the person is held is void. Id. at 728-29, 516 N.W.2d at 716. A habeas corpus petition requires us to examine whether a jurisdictional defect affects the trial court's authority for the detention or imprisonment of a person, or whether the court's order is unconstitutional. J.V. v. Barron, 112 Wis. 2d 256, 261, 332 N.W.2d 796, 799 (1983).
To determine whether Jacobus's judgment of conviction contravenes state policy against criminally charging alcoholics or intoxicated persons with consuming alcohol, we must construe § 51.45(1), STATS. Statutory interpretation presents a question of law which we review de novo. State ex rel. Frederick v. McCaughtry, 173 Wis. 2d 222, 225, 496 N.W.2d 177, 179 (Ct. App. 1992). In construing a statute, our purpose is to discern the legislature's intent and give it effect. Id. We examine the statute's language, and, absent ambiguity, it is our duty to give the language its ordinary meaning. Id. at 225-26, 496 N.W.2d at 179.
The State initially contends that Jacobus has waived his right to contest his incarceration because he entered no contest pleas. A plea of guilty or no contest, when knowingly and voluntarily made, waives all non-jurisdictional defects and defenses. State v. Dietzen, 164 Wis. 2d 205, 210, 474 N.W.2d 753, 755 (Ct. App. 1991). Jurisdictional defects involve the trial court's *789personal jurisdiction over the person of the defendant or the court's jurisdiction over the subject matter of the proceeding. Id. Criminal subject matter jurisdiction involves the power of a court to inquire into the charge of the crime, to apply the law, and to declare the punishment. Id. Subject matter jurisdiction is derived from law and cannot be waived nor conferred by consent. Id. at 210-11, 474 N.W.2d at 755. Indeed, a court does not have subject matter jurisdiction over a nonexistent crime. Id. at 211, 474 N.W.2d at 755.
Jacobus's claim, liberally construed, challenges the trial court's authority to enter a judgment of conviction for actions that the legislature has expressly provided cannot form the basis of a criminal charge. His argument is essentially that the court lacked subject matter jurisdiction to enter the judgment that it did. We agree with Jacobus and conclude that a defendant cannot waive a defect with regard to a guilty plea for an act which is not a crime. Accordingly, Jacobus has not waived his right to contest his incarceration.
Turning to the merits of Jacobus's appeal, he contends that his conviction conflicts with § 51.45(1), Stats., which provides that alcoholics and intoxicated persons may not be subjected to criminal prosecution because of their consumption of alcohol, but should be treated instead. He argues that the plain language of § 51.45(1) prohibits the State from criminally charging an alcoholic or intoxicated person with consuming alcohol. Because three of the five bail jumping charges were based solely upon Jacobus's consumption of alcohol, the only factual basis for the charges is that he was intoxicated. This is exactly what § 51.45(1) prohibits. This interpretation of § 51.45(1) does not prevent the *790State from prohibiting alcohol consumption as a condition of bail, parole, or probation. The penalty, however, can only be a revocation of that status and not a separate criminal charge.
The State responds that the legislative-history of § 51.45(1), Stats., supports its position that Jacobus's charges do not contravene state policy. This history explains that § 51.45(1) does not affect present laws against driving while intoxicated and other crimes committed by persons under the influence of alcohol. See also § 51.45(17)(a).3 The State also argues that the statute was intended to absolve alcoholics from criminal prosecution based solely upon their consumption of alcohol but does not provide a defense against prosecution for violation of other laws committed while under the influence. But three of Jacobus's bail jumping charges were based solely upon his consumption of alcohol. That the State identified the offense as "bail jumping" rather than "intoxication" or "drunkenness" is irrelevant. Had Jacobus committed a crime while he was intoxicated, § 51.45(1) would not be a defense.
We conclude that the trial court's order must be reversed and the petition for a writ of habeas corpus granted. The three bail jumping charges based solely on his consumption of alcohol will be dismissed. Since Jacobus negotiated the plea agreement with the belief that he would be subjected to eight criminal charges and now he faces only five, we will allow him to withdraw the entire plea agreement. Thus, the court must schedule a new trial on the remaining charges.
*791By the Court. — Order reversed and cause remanded with directions.
Section 51.45(1), Stats., provides: "It is the policy of this state that alcoholics and intoxicated persons may not be sub*787jected to criminal prosecution because of their consumption of alcohol beverages but rather should be afforded a continuum of treatment in order that they may lead normal lives as productive members of society."
These three charges were in case No. 92 CM 256.
Section 51.45(17)(a), Stats., provides: "Nothing in this section affects any law, ordinance or rule the violation of which is punishable by fíne, forfeiture or imprisonment."