Section 22. Notwithstanding any general or special law to the contrary, no municipality or public entity shall be liable under this chapter for, or related to, the presence, release or threat of release of oil or any hazardous material related to a dam, as defined in section 44 of chapter 253, that occurred prior to the date a dam was acquired by a municipality or public entity; provided, however, that an activity conducted by a municipality or public entity that involves the management or removal of oil or hazardous material in relation to the management, maintenance or removal of a dam shall be performed in accordance with applicable environmental laws and permits.