[Validator] Fixed: The state of the XML/YAML loaders was changed even if an exception was thrown upon loading

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #12158
| License       | MIT
| Doc PR        | -
There's a separate test (testLoadClassMetadataThrowsExceptionIfNotAnArray) asserting that the InvalidArgumentException is thrown in the simple case (without try-catch).