| In org.hibernate.boot.cfgxml.internal.ConfigLoader#loadConfigXmlFile(File) A FileInputStream is opened but never closed. This produces a resource-leak where the input file is kept open much longer than necessary. It is particularly problematicin web-applications, where the desire is to have near-zero downtime. It prevents a modification of the hibernate configuration while the web application server is running. It must first be stopped before the hibernate configuration can be edited. This method should close the FileInputStream in a finally block:
public LoadedConfig loadConfigXmlFile(File cfgXmlFile) {
try {
final JaxbCfgHibernateConfiguration jaxbCfg = jaxbProcessorHolder.getValue().unmarshal(
new FileInputStream( cfgXmlFile ),
new Origin( SourceType.FILE, cfgXmlFile.getAbsolutePath() )
);
return LoadedConfig.consume( jaxbCfg );
}
catch (FileNotFoundException e) {
throw new ConfigurationException(
"Specified cfg.xml file [" + cfgXmlFile.getAbsolutePath() + "] does not exist"
);
}
}
The jaxbProcessorHolder object clearly cannot require the stream to remain open for any kind of background processes, because the same jaxbProcessorHolder is called in the method #loadConfigXmlUrl(URL url) where the opened InputStream is correctly closed. |