Daily WTF: ehcache startup code
I found this gem in the ehcache library while debugging my own code and using the thrown and uncaught exception breakpoint filter from Eclipse (in ConfigurationHelper:
public final BootstrapCacheLoader createBootstrapCacheLoader(
CacheConfiguration.BootstrapCacheLoaderFactoryConfiguration factoryConfiguration) throws CacheException {
String className = null;
BootstrapCacheLoader bootstrapCacheLoader = null;
try {
className = factoryConfiguration.fullyQualifiedClassPath;
} catch (Throwable t) {
//No class created because the config was missing
}
if (className == null || className.length() == 0) {
LOG.debug("No BootstrapCacheLoaderFactory class specified. Skipping...");
} else {
BootstrapCacheLoaderFactory factory = (BootstrapCacheLoaderFactory)
ClassLoaderUtil.createNewInstance(className);
Properties properties = PropertyUtil.parseProperties(factoryConfiguration.getProperties());
return factory.createBootstrapCacheLoader(properties);
}
return bootstrapCacheLoader;
}
Notice that the parameter given to this method can be null. I always suspected that using an if-statement to check for null-ness was an over-engineered approach.