ANNAPOLIS, Md. — Companies in the final running for licenses to grow medical marijuana should be able to defend their multimillion-dollar investments against a legal challenge over how those finalists were picked, an attorney for the state argued Thursday in court.

The Court of Appeals, Maryland’s top judicial body, heard oral arguments about whether those companies should be allowed to intervene in a lawsuit challenging the government’s selection of finalists. At issue is a decision by a lower court judge that barred the finalists from involvement in the case.

Alternative Medicine Maryland, an applicant not chosen, alleges in a lawsuit that the Maryland Medical Cannabis Commission didn’t consider the racial diversity of the applicants for licenses as required. The group’s attorney, Byron Warnken, has argued that the government agency violated state law in choosing finalists.

An order by Baltimore Circuit Court Judge Barry Williams prohibits the finalists from intervening in the suit.

Yet Julia Bernhardt, an assistant attorney general, said the finalists have a direct economic interest in the lawsuit’s outcome. She added that the medical cannabis commission can’t represent them, because it defends the public interest.

“There’s just something unseemly with charging a regulating body with protecting the economic interest of the very market participants that it’s regulating,” Bernhardt told the court. “It’s just not workable.”

She called for the Court of Appeals to reverse Williams’ decision.

Maryland law allows 15 medical marijuana growers. So far, the commission has only awarded one license. Some growers have hoped to make medical marijuana available to patients by the end of the summer.

The lawyer for Alternative Medicine Maryland, Warnken, said finalists for the licenses shouldn’t be involved in the case.

“Private companies who may have benefited from such a violation should not be permitted to intervene in the challenge to the government’s failures,” Warnken said.

But Arnold Weiner, representing the finalists, noted that his client companies have invested tens of millions of dollars in their businesses. He also said there is nothing speculative about the harm that will be caused the companies, if the court issues an injunction. He said one company has $175,000 in monthly expenses, with no ability to generate income.

“We have found no case where people had an economic interest that was even approaching ours where they were denied intervention,” Weiner told the court.

Maryland’s medical marijuana rollout has been delayed by setbacks for more than four years. The state approved its first medical marijuana law in 2013. The effort stalled, however, because it required academic medical centers to run the programs, and none stepped forward. The law was changed in 2014 to allow doctors certified by a state commission to recommend marijuana for patients with debilitating, chronic or severe illnesses.