Existing light fixture is connected to 2 white wires, black wires are capped

light

enter image description here

I started to replace a light fixture in a closet and discovered that although 2 wires (each containing a black, white, and ground wire) come into the box, only the white wires are connected to the fixture (one on each side). Black and ground wires are connected separately, but not attached to the fixture. See picture.
The light is controlled by a single switch. How can the light work (it does if the switch is turned on) without a black wire?

Best Answer

It looks like a switch loop that was wired backwards. The always hot of a switch loop should be white and the switched hot should be black with a marking on the white always hot to identify it as a hot. I have seen this many times, it is easy to fix by swapping the white and black at each end and then marking the white wire with a black sharpie or black tape (any color other than green, gray or white would meet code)