SAN DIEGO—Consuming alcohol is illegal on this city’s famous beaches. But, thanks to a loophole authorities are now trying to close, drinking a few feet from shore is not.

That’s why, this past Saturday afternoon, Jon Kraemer sat atop an inflated air mattress, sipping a Bud Light he pulled from a floating cooler.

The 26-year-old pharmaceutical salesman was tipsy and carefree and dangling his feet in the water, despite the dozen police officers standing on shore making sure no booze was consumed on land.