From 858859caf3addb6b77677631867a8660c5fdc12f Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Thu, 26 Jan 2017 02:09:39 +0000 Subject: [engine] remove useless isXXXEnabled() tests git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/trunk@1780311 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/org/apache/velocity/Template.java | 5 +---- .../apache/velocity/runtime/ParserPoolImpl.java | 5 +---- .../apache/velocity/runtime/RuntimeInstance.java | 21 ++++++--------------- .../velocity/runtime/VelocimacroFactory.java | 8 ++------ .../apache/velocity/runtime/directive/Parse.java | 2 +- .../velocity/runtime/parser/node/ASTReference.java | 2 +- .../runtime/resource/ResourceManagerImpl.java | 2 +- .../resource/loader/ClasspathResourceLoader.java | 5 +---- .../resource/loader/DataSourceResourceLoader.java | 14 ++++---------- .../resource/loader/FileResourceLoader.java | 5 +---- .../runtime/resource/loader/JarHolder.java | 11 +++-------- .../runtime/resource/loader/JarResourceLoader.java | 5 +---- .../runtime/resource/loader/ResourceLoader.java | 20 +++++++------------- .../resource/loader/StringResourceLoader.java | 21 ++++++--------------- .../runtime/resource/loader/URLResourceLoader.java | 4 ++-- .../velocity/util/introspection/ClassFieldMap.java | 11 ++++------- .../velocity/util/introspection/ClassMap.java | 13 +++++-------- .../velocity/util/introspection/UberspectImpl.java | 22 ++++++++-------------- 18 files changed, 55 insertions(+), 121 deletions(-) (limited to 'velocity-engine-core') diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/Template.java b/velocity-engine-core/src/main/java/org/apache/velocity/Template.java index 6c0bb5fd..8222c277 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/Template.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/Template.java @@ -368,10 +368,7 @@ public class Template extends Resource else { Logger renderingLog = rsvc.getLog("rendering"); - if (renderingLog.isDebugEnabled()) - { - renderingLog.debug(stop.getMessage()); - } + renderingLog.debug(stop.getMessage()); } } catch (IOException e) diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/ParserPoolImpl.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/ParserPoolImpl.java index 8ce0fb09..d59870a1 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/ParserPoolImpl.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/ParserPoolImpl.java @@ -53,10 +53,7 @@ public class ParserPoolImpl implements ParserPool { pool.put(rsvc.createNewParser()); } - if (log.isDebugEnabled()) - { - log.debug("Created '{}' parsers.", max); - } + log.debug("Created '{}' parsers.", max); } /** diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java index 88f3cc32..98be3791 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java @@ -459,10 +459,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices /* populate 'defaultEncoding' member */ defaultEncoding = getString(INPUT_ENCODING, ENCODING_DEFAULT); - if (log.isDebugEnabled()) - { - log.debug("Default Properties resource: {}", DEFAULT_RUNTIME_PROPERTIES); - } + log.debug("Default Properties resource: {}", DEFAULT_RUNTIME_PROPERTIES); } catch (IOException ioe) { @@ -1028,10 +1025,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices for( int i = 0; i < userdirective.length; i++) { loadDirective(userdirective[i]); - if (log.isDebugEnabled()) - { - log.debug("Loaded User Directive: {}", userdirective[i]); - } + log.debug("Loaded User Directive: {}", userdirective[i]); } } @@ -1229,12 +1223,9 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices /* * if we couldn't get a parser from the pool make one and log it. */ - if (log.isInfoEnabled()) - { - log.info("Runtime : ran out of parsers. Creating a new one. " - + " Please increment the parser.pool.size property." - + " The current value is too small."); - } + log.info("Runtime : ran out of parsers. Creating a new one. " + + " Please increment the parser.pool.size property." + + " The current value is too small."); parser = createNewParser(); keepParser = false; } @@ -1416,7 +1407,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices { throw stop; } - else if (log.isDebugEnabled()) + else { log.debug(stop.getMessage()); } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java index c1bfb954..e8951555 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java @@ -376,10 +376,7 @@ public class VelocimacroFactory { vmManager.addVM(name, macroBody, macroArgs, definingTemplate, replaceAllowed); } - if (log.isDebugEnabled()) - { - log.debug("added VM {}: source={}", name, definingTemplate); - } + log.debug("added VM {}: source={}", name, definingTemplate); return true; } @@ -437,8 +434,7 @@ public class VelocimacroFactory * causes false alarms when several concurrent threads simultaneously (re)parse * some macro */ - if (log.isDebugEnabled()) - log.debug("VM addition rejected : {} : inline not allowed to replace existing VM", name); + log.debug("VM addition rejected : {} : inline not allowed to replace existing VM", name); return false; } } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Parse.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Parse.java index e5c22bfb..00a40d69 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Parse.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Parse.java @@ -149,7 +149,7 @@ public class Parse extends InputBase * does it have a value? If you have a null reference, then no. */ Object value = node.jjtGetChild(0).value( context ); - if (value == null && log.isDebugEnabled()) + if (value == null) { log.debug("#parse(): null argument at {}", StringUtils.formatFileString(this)); } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java index c8f713bc..6801ae61 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java @@ -512,7 +512,7 @@ public class ASTReference extends SimpleNode writer.write(morePrefix); writer.write(localNullString); - if (logOnNull && referenceType != QUIET_REFERENCE && log.isDebugEnabled()) + if (logOnNull && referenceType != QUIET_REFERENCE) { log.debug("Null reference [template '{}', line {}, column {}] : {} cannot be resolved.", getTemplateName(), this.getLine(), this.getColumn(), this.literal()); diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java index d96f0901..58acd8ba 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java @@ -441,7 +441,7 @@ public class ResourceManagerImpl * multi-path support - will revisit and fix */ - if (logWhenFound && log.isDebugEnabled()) + if (logWhenFound) { log.debug("ResourceManager: found {} with loader {}", resourceName, resourceLoader.getClassName()); diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java index 6f33e44d..d3a2f1b8 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.java @@ -85,10 +85,7 @@ public class ClasspathResourceLoader extends ResourceLoader */ public void init( ExtProperties configuration) { - if (log.isTraceEnabled()) - { - log.trace("ClasspathResourceLoader : initialization complete."); - } + log.trace("ClasspathResourceLoader : initialization complete."); } /** diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java index dc916d7f..a5394e75 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java @@ -149,21 +149,15 @@ public class DataSourceResourceLoader extends ResourceLoader if (dataSource != null) { - if (log.isDebugEnabled()) - { - log.debug("DataSourceResourceLoader: using dataSource instance with table \"{}\"", tableName); - log.debug("DataSourceResourceLoader: using columns \"{}\", \"{}\" and \"{}\"", keyColumn, templateColumn, timestampColumn); - } + log.debug("DataSourceResourceLoader: using dataSource instance with table \"{}\"", tableName); + log.debug("DataSourceResourceLoader: using columns \"{}\", \"{}\" and \"{}\"", keyColumn, templateColumn, timestampColumn); log.trace("DataSourceResourceLoader initialized."); } else if (dataSourceName != null) { - if (log.isDebugEnabled()) - { - log.debug("DataSourceResourceLoader: using \"{}\" datasource with table \"{}\"", dataSourceName, tableName); - log.debug("DataSourceResourceLoader: using columns \"{}\", \"{}\" and \"{}\"", keyColumn, templateColumn, timestampColumn); - } + log.debug("DataSourceResourceLoader: using \"{}\" datasource with table \"{}\"", dataSourceName, tableName); + log.debug("DataSourceResourceLoader: using columns \"{}\", \"{}\" and \"{}\"", keyColumn, templateColumn, timestampColumn); log.trace("DataSourceResourceLoader initialized."); } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java index da92b770..33cfb734 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java @@ -67,10 +67,7 @@ public class FileResourceLoader extends ResourceLoader */ public void init( ExtProperties configuration) { - if (log.isTraceEnabled()) - { - log.trace("FileResourceLoader : initialization starting."); - } + log.trace("FileResourceLoader : initialization starting."); paths.addAll( configuration.getVector("path") ); diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarHolder.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarHolder.java index 4f5a5d0c..8a0c548a 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarHolder.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarHolder.java @@ -59,10 +59,7 @@ public class JarHolder this.urlpath=urlpath; init(); - if (log.isDebugEnabled()) - { - log.debug("JarHolder: initialized JAR: {}", urlpath); - } + log.debug("JarHolder: initialized JAR: {}", urlpath); } /** @@ -72,10 +69,8 @@ public class JarHolder { try { - if (log.isDebugEnabled()) - { - log.debug("JarHolder: attempting to connect to {}", urlpath); - } + log.debug("JarHolder: attempting to connect to {}", urlpath); + URL url = new URL( urlpath ); conn = (JarURLConnection) url.openConnection(); conn.setAllowUserInteraction(false); diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java index 341419b1..ded365bb 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java @@ -109,10 +109,7 @@ public class JarResourceLoader extends ResourceLoader private void loadJar( String path ) { - if (log.isDebugEnabled()) - { - log.debug("JarResourceLoader : trying to load \"{}\"", path); - } + log.debug("JarResourceLoader : trying to load \"{}\"", path); // Check path information if ( path == null ) diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java index 41f74507..46e83aaa 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java @@ -246,11 +246,8 @@ public abstract class ResourceLoader } catch (ResourceNotFoundException e) { - if (log.isDebugEnabled()) - { - log.debug("Could not load resource '{}' from ResourceLoader {}", - resourceName, this.getClass().getName()); - } + log.debug("Could not load resource '{}' from ResourceLoader {}", + resourceName, this.getClass().getName()); } finally { @@ -263,14 +260,11 @@ public abstract class ResourceLoader } catch (Exception e) { - if (log.isErrorEnabled()) - { - String msg = "While closing InputStream for resource '" + - resourceName + "' from ResourceLoader " + - this.getClass().getName(); - log.error(msg, e); - throw new VelocityException(msg, e); - } + String msg = "While closing InputStream for resource '" + + resourceName + "' from ResourceLoader " + + this.getClass().getName(); + log.error(msg, e); + throw new VelocityException(msg, e); } } return (reader != null); diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/StringResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/StringResourceLoader.java index 06cf1c6d..ad795e08 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/StringResourceLoader.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/StringResourceLoader.java @@ -223,7 +223,7 @@ public class StringResourceLoader extends ResourceLoader if (isStatic) { this.repository = getRepository(repoName); - if (repository != null && log.isDebugEnabled()) + if (repository != null) { log.debug("Loaded repository '{}' from static repo store", repoName); } @@ -231,7 +231,7 @@ public class StringResourceLoader extends ResourceLoader else { this.repository = (StringResourceRepository)rsvc.getApplicationAttribute(repoName); - if (repository != null && log.isDebugEnabled()) + if (repository != null) { log.debug("Loaded repository '{}' from application attributes", repoName); } @@ -267,11 +267,8 @@ public class StringResourceLoader extends ResourceLoader if (encoding != null && !this.repository.getEncoding().equals(encoding)) { - if (log.isDebugEnabled()) - { - log.debug("Changing the default encoding of string repository '{}' from {} to {}", - repoName, this.repository.getEncoding(), encoding); - } + log.debug("Changing the default encoding of string repository '{}' from {} to {}", + repoName, this.repository.getEncoding(), encoding); this.repository.setEncoding(encoding); } } @@ -285,10 +282,7 @@ public class StringResourceLoader extends ResourceLoader public StringResourceRepository createRepository(final String className, final String encoding) { - if (log.isDebugEnabled()) - { - log.debug("Creating string repository using class {}...", className); - } + log.debug("Creating string repository using class {}...", className); StringResourceRepository repo; try @@ -317,10 +311,7 @@ public class StringResourceLoader extends ResourceLoader repo.setEncoding(RuntimeConstants.ENCODING_DEFAULT); } - if (log.isDebugEnabled()) - { - log.debug("Default repository encoding is {}", repo.getEncoding()); - } + log.debug("Default repository encoding is {}", repo.getEncoding()); return repo; } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java index 1c3ce3d9..750accde 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/URLResourceLoader.java @@ -122,7 +122,7 @@ public class URLResourceLoader extends ResourceLoader if (reader != null) { - if (log.isDebugEnabled()) log.debug("URLResourceLoader: Found '{}' at '{}'", name, roots[i]); + log.debug("URLResourceLoader: Found '{}' at '{}'", name, roots[i]); // save this root for later re-use templateRoots.put(name, roots[i]); @@ -139,7 +139,7 @@ public class URLResourceLoader extends ResourceLoader } catch (IOException e) {} } - if (log.isDebugEnabled()) log.debug("URLResourceLoader: Exception when looking for '{}' at '{}'", name, roots[i], ioe); + log.debug("URLResourceLoader: Exception when looking for '{}' at '{}'", name, roots[i], ioe); // only save the first one for later throwing if (exception == null) diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/ClassFieldMap.java b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/ClassFieldMap.java index c01f465b..6bc7481f 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/ClassFieldMap.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/ClassFieldMap.java @@ -67,7 +67,7 @@ public class ClassFieldMap this.clazz = clazz; this.log = log; - if (debugReflection && log.isDebugEnabled()) + if (debugReflection) { log.debug("================================================================="); log.debug("== Class: {}", clazz); @@ -75,7 +75,7 @@ public class ClassFieldMap fieldCache = createFieldCache(); - if (debugReflection && log.isDebugEnabled()) + if (debugReflection) { log.debug("================================================================="); } @@ -148,7 +148,7 @@ public class ClassFieldMap private void populateFieldCacheWith(Map fieldCache, Class classToReflect) { - if (debugReflection && log.isDebugEnabled()) + if (debugReflection) { log.debug("Reflecting {}", classToReflect); } @@ -167,10 +167,7 @@ public class ClassFieldMap } catch (SecurityException se) // Everybody feels better with... { - if (log.isDebugEnabled()) - { - log.debug("While accessing fields of {}:", classToReflect, se); - } + log.debug("While accessing fields of {}:", classToReflect, se); } } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/ClassMap.java b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/ClassMap.java index cc447459..16a3baae 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/ClassMap.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/ClassMap.java @@ -78,7 +78,7 @@ public class ClassMap this.clazz = clazz; this.log = log; - if (debugReflection && log.isDebugEnabled()) + if (debugReflection) { log.debug("================================================================="); log.debug("== Class: {}", clazz); @@ -86,7 +86,7 @@ public class ClassMap methodCache = createMethodCache(conversionHandler); - if (debugReflection && log.isDebugEnabled()) + if (debugReflection) { log.debug("================================================================="); } @@ -170,7 +170,7 @@ public class ClassMap private void populateMethodCacheWith(MethodCache methodCache, Class classToReflect) { - if (debugReflection && log.isDebugEnabled()) + if (debugReflection) { log.debug("Reflecting {}", classToReflect); } @@ -189,10 +189,7 @@ public class ClassMap } catch (SecurityException se) // Everybody feels better with... { - if (log.isDebugEnabled()) - { - log.debug("While accessing methods of {}:", classToReflect, se); - } + log.debug("While accessing methods of {}:", classToReflect, se); } } @@ -304,7 +301,7 @@ public class ClassMap { cache.put(methodKey, method); methodMap.add(method); - if (debugReflection && log.isDebugEnabled()) + if (debugReflection) { log.debug("Adding {}", method); } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/UberspectImpl.java b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/UberspectImpl.java index 14e6a5e6..fa57e8c9 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/UberspectImpl.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/UberspectImpl.java @@ -181,24 +181,18 @@ public class UberspectImpl implements Uberspect, RuntimeServicesAware } else if (obj instanceof Iterator) { - if (log.isDebugEnabled()) - { - log.debug("The iterative object in the #foreach() loop at {}" + - " is of type java.util.Iterator. Because " + - "it is not resettable, if used in more than once it " + - "may lead to unexpected results.", i); - } + log.debug("The iterative object in the #foreach() loop at {}" + + " is of type java.util.Iterator. Because " + + "it is not resettable, if used in more than once it " + + "may lead to unexpected results.", i); return ((Iterator) obj); } else if (obj instanceof Enumeration) { - if (log.isDebugEnabled()) - { - log.debug("The iterative object in the #foreach() loop at {}" + - " is of type java.util.Enumeration. Because " + - "it is not resettable, if used in more than once it " + - "may lead to unexpected results.", i); - } + log.debug("The iterative object in the #foreach() loop at {}" + + " is of type java.util.Enumeration. Because " + + "it is not resettable, if used in more than once it " + + "may lead to unexpected results.", i); return new EnumerationIterator((Enumeration) obj); } else -- cgit v1.2.3