ehcache / ehcache3

Ehcache 3.x line
http://www.ehcache.org
Apache License 2.0
2k stars 578 forks source link

Ehcache 3.x incorrectly working with uri classpath://ehcache.xml - org.xml.sax.SAXParseException: Content is not allowed in prolog. #3195

Open sergmain opened 1 year ago

sergmain commented 1 year ago

This bug is happened in following environment - Spring Boot 3 + Tomcat + hibernate + Ehcache

Cause: In such configuration Tomcat override a list of URL handlers by registering itself as URLStreamHandlerFactory. as a result a new handler for protocol 'classpath' is adding to list of handlers in java.net.URL

As a result the following code in hibernate isn't generating MalformedURLException for classpath://ehcache.xml because 'classpath' now is a correct protocol https://github.com/hibernate/hibernate-orm/blob/8461ba2078657caf58930b9485020fe89aff4afe/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java#L134

and as following result hibernate is calling ehcache with Url(classpath://ehcache.xml). In 'normal' situation Ehcache would be called with full path to file ehcache.xml

When Ehcache is starting processing Url(classpath://ehcache.xml) for unknown reason stream contains rubbish data instead of actual content of ehcache.xml

there is a simple project for reproducing a bug:

https://github.com/sergmain/ehcache-bug-3195

java.vendor.version: Temurin-17.0.7+7

jhouserizer commented 1 year ago

Thanks, we will have a look.