Appeal from a judgment of the County Court of Warren County (Hall, J.), rendered January 10, 2007, convicting defendant upon his plea of guilty of the crimes of criminal sale of a controlled substance in the third degree and attempted assault in the second degree.
Defendant pleaded guilty to criminal sale of a controlled substance in the third degree and attempted assault in the second degree and waived his right to appeal. County Court thereafter sentenced him to 11 years in prison and three years of postrelease supervision for the criminal sale conviction and 2 to 4 years in prison for the attempted assault conviction, with the prison terms ordered to run concurrently. Defendant now appeals.
Defendant contends that County Court’s pronouncement of *1099him as a second felony offender was improper because there was not compliance with CPL 400.21. We preliminarily note that, inasmuch as such a claim implicates the legality of defendant’s sentence, his waiver of appeal does not preclude him from raising it (see People v Ladson, 30 AD3d 836, 837 [2006]). Turning to the merits, CPL 400.21 (2) requires that a predicate felony offender statement be filed before the sentence is imposed. In this case, however, the statement was not filed and defendant was not afforded an opportunity to be heard on the matter until after he had already been sentenced. Moreover, defendant never agreed to be sentenced as a second felony offender during the plea allocution and therefore cannot be said to have waived his rights under CPL 400.21 (see People v Anthony, 52 AD3d 864, 865 [2008]). Similarly, defendant’s failure to controvert the statement after his sentence had already been imposed does not validate or otherwise constitute a waiver of the sentence (see id.). Accordingly, because the mandates of CPL 400.21 were not satisfied, defendant’s sentence is invalid as a matter of law (see id.). We must, therefore, remit this matter to County Court for resentencing.
In view of our disposition, defendant’s assertion that his sentence is harsh and excessive is academic.
Cardona, PJ., Rose, Kavanagh and Stein, JJ., concur. Ordered that the judgment is modified, on the law, by vacating the sentence imposed; matter remitted to the County Court of Warren County for further proceedings not inconsistent with this Court’s decision; and, as so modified, affirmed.