Fix for reducing length in StatefulArray, fixes #17325.