Calling org.springframework.core.io.Resource#exists is called on a resource inside a JAR file (actually org.springframework.core.io.AbstractFileResolvingResource#exists in such cases), an input stream of whether the same or another resource in the same JAR file is (accidentally) closed. Trying to read (or continue reading) from such an input stream afterwards results in an java.io.IOException: Stream closed. The exist method should just answer it's intended question, but it should never change the state of an input stream.

This issue was introduced with v6.2.7, apparently with the fix for #34796.

I've created a small test project that shows some different combinations of resource reading along with exists checks: jar-resource-loader-test.zip

Comment From: ibrahimesseddyq

i can work on this

Comment From: bclozel

@ibrahimesseddyq thanks for the help but this is already assigned

Comment From: jhoeller

@marcrohlfs a revision is available in the latest 6.2.8 snapshot now, only closing the JarFile in case of useCaches=false just like JarURLConnection internally does. Please give it a try in your scenario before the 6.2.8 release (scheduled for Thursday next week)...

Comment From: marcrohlfs

Many thanks for providing a fix that fast! I updated our project to the latest 6.2.8 snapshot and the failures that occurred with 6.2.7 have vanished from our integration test suites. Many thanks!

Comment From: jhoeller

Good to hear, thanks for the immediate testing!