Thermal expansion of Josephson junctions as an elastic response to an effective stress field