Nothing unlawful about it. In some auto pistols, putting the barrel from a longer-slide gun into a shorter-slide pistol can cause malfunction and eventual breakage, since the lugs may be cut differently. I haven't heard of anything in that vein happening with Glocks, and honestly have no experience with it since all my Glocks have barrels the same length the slide was designed for.
Chane, I'm gonna refer you upstream to JR in the Glock Pistols section of GATE. I am sure he'll be able to answer that question better than I.
Sorry I couldn't be more help,