On Fri, 11 Oct 2024 11:46:40 GMT, Eirik Bjørsnøs <[email protected]> wrote:
> 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.
Hello Eirik, from what I can see, the fact that a `ClassFormatError` thrown
from `URLClassLoader` has a suppressed exception and that the suppressed
exception would contain CRC failure related exception message is merely an
implementation detail (which should be free to change any time). I think
asserting this internal detail through a test case isn't necessary.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/21469#issuecomment-2408854972