Fix a potential NPE which can apparently happen in very exotic cases (actually, it rather points to a Java class library bug).