In January, Christopher Cleary posted on Facebook that he was “planning on shooting up a public place,” according to police, “killing as many girls as I see.”

The next day he was arrested in Provo, Utah, on the morning of the Women’s March.

It wasn’t the first time he threatened women with violence. The 27-year-old Colorado man blamed years of romantic rejection for his anger toward women, according to a police affidavit.

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, and 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 that 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, Colo., district attorney’s office, told The Washington Post that while judges had sought to find an alternative to prison in line with Colorado law, 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 a 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 that 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 although 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.”

Women were looking for modeling gigs on Craigslist. Then they were pulled into an alleged sex trafficking scheme.

The recent criminal case could signal a shift for online pornography, experts say

What the victims of the country’s most prolific serial killer had in common

This week, the FBI announced that Samuel Little confessed to 93 murders spanning 35 years