Pennsylvania gun control advocates on Wednesday asked the state's top court to knock down a 2014 law allowing gun-rights lobbying groups to sue cities that adopt gun restrictions and recoup legal costs if they prevail.

Firearms advocates, including the National Rifle Association, contend the law is necessary to prevent gun owners from becoming ensnared by a patchwork of municipal ordinances that violate their right to bear arms.

Gun control advocates challenged the law on a technicality - that it passed as part of what they called an unrelated piece of legislation.

"These two bills were cobbled together for political expediency at the end of the legislative session," Martin Black, representing five Democratic lawmakers who sued to overturn the law, told the Pennsylvania Supreme Court. More than 80 towns across Pennsylvania repealed gun laws - ranging from requirements that owners report lost or stolen firearms to bans on guns in public parks - rather than face hundreds of thousands of dollars in legal bills to defend ordinances that were seldom enforced. Five municipalities, including Philadelphia and Pittsburgh, have faced lawsuits under the law.

RELATED: Anti-gun series looks to combat violence through love

The Second Amendment of the U.S. Constitution protects the right to bear arms, and efforts to regulate gun ownership are often fiercely contested.

Wednesday's arguments focused on the tortured legislative history of the bill and whether its passage violated a provision of the state's Constitution that specifies that laws must focus on a single issue. 

A lower court found last June that the passage was unconstitutional because Republican lawmakers tucked the firearms legislation into a bill dealing with scrap metal.

That bill passed on the final day of the 2014 legislative session and was so rushed that Republican Governor Tom Corbett signed the wrong bill.  

RELATED: Gun owners grill Obama at town hall

Republican legislators said at the time that the language was necessary because towns were ignoring laws that made it a criminal offense for towns to pass gun restrictions.

"What does suing the city over a firearms matter have to do with the theft of copper wire?" asked a skeptical Justice David Wecht.

Attorney Nick Orloff, arguing on behalf of Republican legislators, said both bills dealt with crime prevention. 

"It's meant to deter crime," Orloff said. 

But Shira Goodman, executive director of CeaseFire PA, scoffed at that idea.

"Say the city of Philadelphia passes a soda tax," Goodman said. "If I don't drink soda, I don't get to sue because I didn't pay the tax."