A Federal Court judge says Canada's rules for detaining some foreigners who can't be deported quickly are constitutional though they may not always be applied perfectly.

Judge Simon Fothergill says there are mechanisms built into the law to allow detainees to challenge their detention and the conditions in which they are held, which is enough to make the system constitutional.

In a decision released Tuesday, Fothergill said that if those standards are sometimes not met, "this is a problem of maladministration, not an indication that the statutory scheme is itself unconstitutional."

The constitutional challenge was filed by Alvin Brown, a Jamaican man who was detained for five years before being deported last year.

Brown sought to cap detention at 18 months

The father of six and his supporters argued that foreigners who cannot be deported for various reasons are subjected to cruel and unusual punishment in that they may spend years behind bars never knowing when they might be released.

Brown sought to have the court declare that holding someone for more than six months before deportation is presumptively unconstitutional, and asked it to impose a "hard cap" of 18 months of pre-removal detention.

But Fothergill suggested a higher court should weigh in on whether the Charter of Rights and Freedoms requires a time limit on detention for immigration purposes after which release is mandatory, and certified the issue for appeal.

Brown's lawyer, Jared Will, said he was disappointed by the court's decision.

Jared Will, lawyer for Alvin Brown, launched the landmark constitutional challenge two years ago, calling on the government to justify the practice of indefinite immigration detention. (Paul Smith/CBC)

'End Immigration Detention Network' not giving up

The End Immigration Detention Network, which was a party to the case, said it was prepared to continue its legal battle.

"This is just another step, we were in it for the long haul," said the group's lawyer, Swathi Sekhar.

"In the meantime people continue to be detained indefinitely so it's important now more than ever, now that there's been some kind of light into what's happening, that the public open their eyes and really put pressure on the government to make changes."

Brown came to Canada as a child more than three decades ago and was eventually stripped of his permanent residency after a series of convictions, most of them drug and weapons related.

He was released from criminal custody in early 2011 but border agents detained him months later for violating release conditions.

However, Jamaica refused for some time to issue travel documents and Brown remained in maximum-security detention branded a flight risk and a danger to the public. He was deported in September.