RFR: 8341957: Add test for URLClassLoader loading invalid class with mismatching CRC32
Eirik Bjørsnøs
eirbjo at openjdk.org
Fri Oct 11 15:35:29 UTC 2024
Please review this PR which adds test coverage for the case where `URLClassLoader.defineClass` fails with a `ClassFormatError` _and_ the CRC32 checksum of the class file byte array did not match the CRC32 value stated in the JAR file's CEN header.
In such cases, an `IOException` with the message _"CRC error while extracting entry from JAR file"_ is added as a suppressed exception to the `ClassFormatError`.
Adding a test documents this unspecified, but long-standing behavior.
For good measure, the test also covers the existing behavior of the module system class loader. Since the module system does not add similar suppressed exception on a CRC32 mismatch, this test mostly serves the purpose of documentation.
The test is parameterized, as such it covers all eight combinations of {URLClassLoader/module class loader, valid/invalid class data, valid/invalid CRC checksum}.
Should any of the class loaders change behavior in the future (with or without intent), this test will notice and may need to be updated to document the new behavior. Otherwise, it will catch unintended regressions.
Testing: This is a test-only enhancement PR, no existing tests are updated.
-------------
Commit messages:
- Rename "ClassLoadingContext" -> "ClassLoaderContext"
- Make the test parameterized allows testing all eight combinations of class loader, valid class data, valid CRC in a single test
- Add tests for the cases where there is a CRC mismatch, but the class file data is valid
- Spell fix
- Rename "zipFile" to "jarFile"
- Add javadoc documentation to tests
- Add test to verify that URLClassLoader checks CRC32 of class file data when defineClass fails with ClassFormatError
Changes: https://git.openjdk.org/jdk/pull/21469/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=21469&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8341957
Stats: 280 lines in 1 file changed: 280 ins; 0 del; 0 mod
Patch: https://git.openjdk.org/jdk/pull/21469.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/21469/head:pull/21469
PR: https://git.openjdk.org/jdk/pull/21469
More information about the core-libs-dev
mailing list