014-code commented on PR #30046:
URL: https://github.com/apache/flink/pull/30046#issuecomment-7037369615

   Additional reproduction, design, and validation details:
   
   ### Reproduction and root cause
   
   I compiled the current checkout's four classloader source files and 
exercised them with a real temporary JAR containing a resource. For each 
loading order, the reproducer opens the resource with `getResourceAsStream`, 
reads it, closes the stream, and then closes the classloader. It checks the 
cached `JarFile` through its public API and separately attempts to delete the 
JAR on Windows.
   
   On Java 17, with each loading order repeated three times:
   
   | Configuration | JAR closed after loader close | Windows deletion |
   | --- | --- | --- |
   | Parent-first, no safety-net wrapper | 3/3 | 3/3 succeeded |
   | Child-first, no safety-net wrapper | 3/3 | 3/3 succeeded |
   | Parent-first, safety-net wrapper | 0/3 | 0/3 succeeded |
   | Child-first, safety-net wrapper | 0/3 | 0/3 succeeded |
   
   The wrapper delegates `getResource` to the inner loader but inherits 
`URLClassLoader.getResourceAsStream`. That inherited method records the JAR it 
opens on the wrapper. The wrapper's `close()` only closes the inner loader, 
leaving the wrapper-owned cached JAR open even after the caller closes the 
resource stream.
   
   ### Why delegate the stream lookup
   
   The fix forwards `getResourceAsStream` through `ensureInner()`, consistent 
with the wrapper's existing resource and class-loading methods. The inner 
loader now owns the opened resource and releases it when the wrapper closes it. 
This also retains the existing closed-loader guard and parent-first/child-first 
resource lookup behavior.
   
   Calling `super.close()` on the wrapper is another possible direction, but 
delegation avoids creating a second resource owner in a class intended to 
forward operations to the inner loader. The patch does not change `close()` or 
add a separate cleanup mechanism.
   
   ### Regression test and red-green check
   
   The parameterized test uses a private copy of the existing test JAR for each 
loading order, reads and closes a real class resource, retrieves the cached JAR 
with `JarURLConnection`, closes the loader, and asserts that `JarFile.size()` 
rejects access to the closed JAR. Try-with-resources releases the JAR even when 
the assertion fails.
   
   The assertion does not rely on Windows deletion semantics, sleeps, 
reflective access to JDK internals, or mocked classloaders. Before applying the 
production change, both cases failed because `JarFile.size()` remained 
callable. After the fix, both passed.
   
   The initial red-green run used JUnit Platform Console with the current 
classloader and test-helper sources compiled directly; auxiliary Flink 
dependencies were published 2.2.1 artifacts. Separately, the Maven validation 
built the current reactor modules and compiled all production and test sources 
in `flink-core`. Its selected test classes passed 13/13 tests with no failures, 
errors, or skips. Checkstyle and Spotless also passed.
   
   ### Remaining validation
   
   This stays a draft because full `clean verify` has not passed. The initial 
Maven run was stopped while Apache Rat spent several minutes in 
license-matching regex processing, confirmed by a thread dump. A subsequent run 
compiled successfully but default Surefire forks printed Windows "Access is 
denied" without starting the tests. The successful targeted Maven run therefore 
used `-Drat.skip=true` and `-Dflink.forkCountUnitTest=0`, as documented in the 
PR body.
   
   The full module test suite, default forked execution, full license scan, and 
Linux/macOS execution remain unverified. Same-path JAR replacement was not 
tested separately. These limits are not included in the passing-test claim.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to