Christopher Cleary was arrested in January on the morning of the Women's March in Provo, Utah.

Christopher Cleary had a history of threatening women with violence when he was arrested in January on the morning of the Women's March in Provo, Utah. The 27-year-old Colorado man blamed years of romantic rejection for his anger toward women, according to a police affidavit.

"I'm planning on shooting up a public place," he had posted on Facebook the night before his arrest, according to police, "killing as many girls as I see."

He also had a history of second chances. The Denver resident had twice pleaded guilty to felony stalking charges for harassing and threatening women in his home state, but was sentenced to probation and mental health evaluations. Now, a Utah judge has sentenced Cleary to up to five years in prison on a charge of attempted threat of terrorism.

According to legal experts, the case has pitted the First Amendment right to free speech against public safety concerns, testing the criminal justice system's ability to respond to a man who wrote online that he wanted to be "the next mass shooter."

Judge Christine Johnson's ruling means Cleary could serve the maximum sentence for the charge, despite the prosecution recommending only probation, a move the lead prosecutor told the Associated Press was necessary to secure a guilty plea. It's now up to Utah's parole authorities to decide whether Cleary will serve the full sentence.

The plea agreement meant even without a prison sentence in Utah, Cleary would have been convicted of a felony and sent back to Colorado to serve time for violating probation.

"I don't want to be in the position of guessing what Colorado is going to do," the judge said, the Deseret News reported.

Pam Russell, communications director for the Jefferson County, Colorado, District Attorney's Office, told The Washington Post her office had sought to find an alternative to prison in line with Colorado law, but that Cleary would now face prison when he returns to the state.

"The legislature in Colorado has made it clear that they oppose prison sentences for offenders convicted of low-level felonies," Russell wrote in an email. "The District Attorney's Office believes that he may be a threat to the community and will ask for a prison sentence when he is returned to Colorado for re-sentencing."

Cleary's previous stalking convictions in Colorado, both low-level felonies, were based on harassment and threats against multiple women. In at least one case, he posted the victim's phone number on false Craigslist ads soliciting sex, leading to constant harassment and severe distress, according to a police affidavit. He made frequent threats of violence, such as a text message in 2015 warning a woman, "I own multipul guns I can have u dead in a second."

Colorado police also investigated complaints that Cleary threatened to bomb a grocery store and carry out a mass shooting at a mental health facility.

In the Jan. 19 Facebook post, he blamed his stated plan to kill women on romantic rejection. "All I wanted was to be loved," he wrote, "yet no one cares about me I'm 27 years old and I've never had a girlfriend before and I'm still a virgin."

Before his arrest in Utah, Cleary told police he was just "upset and not thinking clearly," according to the affidavit. At Thursday's trial, defense attorney Dustin Parmley argued the Facebook post "wasn't targeted at anyone in particular. He chose extreme words to express his feelings of frustration," the Deseret News reported.

Amos Guiora, a law professor at the University of Utah, said that while the First Amendment gives considerable protections to even vile speech, "it's really important to view free speech as not unlimited and needing to be perceived from the perspective of the victim."

"When you post 'I'm going to kill all the women I see,'" Guiora said, "that's not an indirect threat."