MARTINEZ — In a decision First Amendment experts have dubbed “outrageous,” a Contra Costa Superior Court judge jailed a San Ramon man for writing about his divorce on the internet — even though his writings were based on material publicly available in court files.

The judge, Bruce C. Mills, insisted in his decision that “matters that are put into court pleadings and brought up in oral argument before the court do not become public thereby” — a position that lawyers say fundamentally misunderstands the nature of court records.

Joseph Sweeney, a judicial reform advocate, served 13 days in County Jail in August after Mills’ ruling, which found that Sweeney’s web postings had violated another judge’s restraining order not to disclose the contents of his ex-wife’s cellphone or computer. The postings described Sweeney’s realizations about her medical history and contact with others that led to the collapse of the marriage.

The information became publicly available in court documents when it was filed without seal by his ex-wife, and in an online appellate court decision upholding the order. As a result, “the cat is out of the bag and the general presumption that publicly filed documents may be read by all carries the day,” said Floyd Abrams, considered among the top First Amendment lawyers in the United States, in an email to this newspaper.

Several other free speech experts also said Mills’ assertion that the information was not public record is flatly wrong. Martin Garbus, widely considered one of the top trial attorneys in the United States, said court documents filed without a sealing order are legally just as public as newspaper articles.

Peter Scheer, executive director of the San-Rafael based First Amendment Coalition, called it “absolutely outrageous to hold this person in contempt and put him in jail. … If the judge thought it was a violation, he could have fined him. … But to have taken the step of throwing him in jail is, I think, just beyond the pale.”

Sweeney, 35, said his jail stay was “a pretty traumatic experience to go through.” He spent the 13 days alone in his Richmond cell, and “the window to the outside was completely frosted opaque glass. I could only tell light and dark.”

It all came about during Sweeney’s long and contentious divorce case. In 2014, another judge ordered him not to share personal information from his wife’s phone after he disclosed information from her text messages to her parents and others. In 2015, after Sweeney’s ex-wife filed the same information in court documents, Sweeney posted a 36-chapter description of his failed marriage online.

His ex-wife then asked that Sweeney be found in contempt of court. In August, Mills, who hears contempt motions and who has five ethics violations on his judicial record, obliged her.

“(Sweeney) was well aware of all of these allegations and all of this information he gleaned from the phones long before it was included in discovery in subsequent court proceedings,” Mills said in his ruling, calling the court records “the fruit of the poisonous tree.”

Mills said in court, according to a transcript, that Sweeney’s actions were “the most egregious” he’d seen in two years hearing contempt cases, and that his online postings were designed to “humiliate, embarrass and harass (Sweeney’s ex-wife).” He gave Sweeney the maximum sentence allowable for five counts of contempt, 25 days at half time.

Mills declined requests for an interview.

Contra Costa Presiding Judge Steven Austin said he was barred from publicly discussing the case but that he was aware of it. But in a letter to a woman who expressed concerns to Austin about the case, he said Mills listened to both sides and did not seem “biased or prejudiced” against Sweeney.

Sweeney is a judicial reform advocate who in March testified to state lawmakers, arguing for an audit of the body that disciplines judges, the California Commission on Judicial Performance (CJP). The state Legislature voted to audit the CJP in August, two days before Mills jailed Sweeney.

It is a body that Mills, a judge since 1995, knows well; It has ruled five times since 2001 that he violated ethics rules. In 2001, commissioners privately admonished him for “attempting to coerce” a defendant into a guilty plea.

In 2013, after Mills met with the judge handling a case where his son was a defendant, and told the judge how he wanted the case to be resolved, the commission found he had “created an appearance of impropriety that undermined public confidence in the impartiality and integrity of the judiciary.”

“As a court, we are always concerned if the Commission on Judicial Performance imposes discipline on any of our judges,” Austin said when asked his opinion of Mills’ record.

A spokeswoman for the commission declined to comment.

Sweeney said under oath that the purpose of his website, which referenced his ex-wife’s last name in its domain, was “to tell my story so that I could begin becoming involved in the judicial reform community.”

His ex-wife’s attorney, Michelene Insalaco, pushed back against that notion, saying, “It’s our position that Joe doesn’t have a legitimate interest in court reform, that his main interest is in harassing (his ex-wife), and that’s what Judge Mills found.” She said that regardless of whether the information was public, Sweeney used it to abuse her client.

Nikki Moore, an attorney for the California Newspaper Publishers Association, said she sympathized with the order’s intent to prevent harassment, but the information being publicly available gave Sweeney a “First Amendment defense.”

“The First Amendment applies to everyone, even jerks,” she said.