Improved: Always check if debug verbose is on when using Debug.logVerbose()

(OFBIZ-10052)

We discussed on this point: http://markmail.org/message/mplvusuqn7oshl4v 
and we agreed about better doing a check when using Debug.logVerbose().

I checked there are 300+ cases like that. Since it's an easy S/R 
This implements it

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1818005 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jacques Le Roux
2017-12-13 12:43:05 +00:00
parent 7e19de9966
commit e0d2057456
96 changed files with 290 additions and 290 deletions
@@ -459,7 +459,7 @@ public final class ComponentConfig {
throw new ComponentException("Error reading container configurations for component: " + this.globalName, ce);
}
if (Debug.verboseOn()) {
Debug.logVerbose("Read component config : [" + rootLocation + "]", module);
if (Debug.verboseOn()) Debug.logVerbose("Read component config : [" + rootLocation + "]", module);
}
}
@@ -55,7 +55,7 @@ public class ComponentResourceHandler implements ResourceHandler {
this.loaderName = loaderName;
this.location = location;
if (Debug.verboseOn()) {
Debug.logVerbose("Created " + this.toString(), module);
if (Debug.verboseOn()) Debug.logVerbose("Created " + this.toString(), module);
}
}
@@ -74,7 +74,7 @@ public class Converters {
public static <S, T> Converter<S, T> getConverter(Class<S> sourceClass, Class<T> targetClass) throws ClassNotFoundException {
String key = sourceClass.getName().concat(DELIMITER).concat(targetClass.getName());
if (Debug.verboseOn()) {
Debug.logVerbose("Getting converter: " + key, module);
if (Debug.verboseOn()) Debug.logVerbose("Getting converter: " + key, module);
}
OUTER:
do {
@@ -195,7 +195,7 @@ OUTER:
sb.append(targetClass.getName());
String key = sb.toString();
if (converterMap.putIfAbsent(key, converter) == null) {
Debug.logVerbose("Registered converter " + converter.getClass().getName(), module);
if (Debug.verboseOn()) Debug.logVerbose("Registered converter " + converter.getClass().getName(), module);
}
}
@@ -85,14 +85,14 @@ public class GroovyUtil {
return null;
}
if (Debug.verboseOn()) {
Debug.logVerbose("Evaluating -- " + expression, module);
Debug.logVerbose("Using Context -- " + context, module);
if (Debug.verboseOn()) Debug.logVerbose("Evaluating -- " + expression, module);
if (Debug.verboseOn()) Debug.logVerbose("Using Context -- " + context, module);
}
try {
GroovyShell shell = new GroovyShell(getBinding(context, expression));
o = shell.evaluate(StringUtil.convertOperatorSubstitutions(expression));
if (Debug.verboseOn()) {
Debug.logVerbose("Evaluated to -- " + o, module);
if (Debug.verboseOn()) Debug.logVerbose("Evaluated to -- " + o, module);
}
// read back the context info
Binding binding = shell.getContext();
@@ -160,7 +160,7 @@ public class GroovyUtil {
Class<?> scriptClassCached = parsedScripts.putIfAbsent(location, scriptClass);
if (scriptClassCached == null) { // putIfAbsent returns null if the class is added to the cache
if (Debug.verboseOn()) {
Debug.logVerbose("Cached Groovy script at: " + location, module);
if (Debug.verboseOn()) Debug.logVerbose("Cached Groovy script at: " + location, module);
}
} else {
// the newly parsed script is discarded and the one found in the cache (that has been created by a concurrent thread in the meantime) is used
@@ -486,16 +486,16 @@ public class HttpClient {
OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream(),
this.streamCharset != null ? this.streamCharset : "UTF-8")) {
if (Debug.verboseOn() || debug)
Debug.logVerbose("Opened output stream", module);
if (Debug.verboseOn()) Debug.logVerbose("Opened output stream", module);
if (arguments != null) {
out.write(arguments);
if (Debug.verboseOn() || debug)
Debug.logVerbose("Wrote arguements (parameters) : " + arguments, module);
if (Debug.verboseOn()) Debug.logVerbose("Wrote arguements (parameters) : " + arguments, module);
}
if (Debug.verboseOn() || debug)
Debug.logVerbose("Flushed and closed buffer", module);
if (Debug.verboseOn()) Debug.logVerbose("Flushed and closed buffer", module);
}
}
@@ -800,7 +800,7 @@ public class ObjectType {
if (value instanceof java.util.Date) return false;
if (Debug.verboseOn()) {
Debug.logVerbose("In ObjectType.isEmpty(Object value) returning false for " + value.getClass() + " Object.", module);
if (Debug.verboseOn()) Debug.logVerbose("In ObjectType.isEmpty(Object value) returning false for " + value.getClass() + " Object.", module);
}
return false;
}
@@ -52,7 +52,7 @@ public class PatternFactory {
}
pattern = compiledPerl5Patterns.putIfAbsentAndGet(stringPattern, pattern);
if (Debug.verboseOn()) {
Debug.logVerbose("Compiled and cached the pattern: '" + stringPattern, module);
if (Debug.verboseOn()) Debug.logVerbose("Compiled and cached the pattern: '" + stringPattern, module);
}
}
return pattern;
@@ -134,7 +134,7 @@ public final class SSLUtil {
List<KeyManager> newKeyManagers = Arrays.asList(getKeyManagers(ks, ksi.getPassword(), alias));
keyMgrs.addAll(newKeyManagers);
if (Debug.verboseOn())
Debug.logVerbose("Loaded another cert store, adding [" + newKeyManagers.size()
if (Debug.verboseOn()) Debug.logVerbose("Loaded another cert store, adding [" + newKeyManagers.size()
+ "] KeyManagers for alias [" + alias + "] and keystore: " + ksi.createResourceHandler()
.getFullLocation(), module);
} else {
@@ -108,7 +108,7 @@ public final class ScriptUtil {
if (iter.hasNext()) {
helperFactory = iter.next();
if (Debug.verboseOn()) {
Debug.logVerbose("ScriptHelper factory set to " + helperFactory.getClass().getName(), module);
if (Debug.verboseOn()) Debug.logVerbose("ScriptHelper factory set to " + helperFactory.getClass().getName(), module);
}
} else {
Debug.logWarning("ScriptHelper factory not found", module);
@@ -140,11 +140,11 @@ public final class ScriptUtil {
.getUtf8()));
script = compilableEngine.compile(reader);
if (Debug.verboseOn()) {
Debug.logVerbose("Compiled script " + filePath + " using engine " + engine.getClass().getName(), module);
if (Debug.verboseOn()) Debug.logVerbose("Compiled script " + filePath + " using engine " + engine.getClass().getName(), module);
}
} catch (ClassCastException e) {
if (Debug.verboseOn()) {
Debug.logVerbose("Script engine " + engine.getClass().getName() + " does not implement Compilable", module);
if (Debug.verboseOn()) Debug.logVerbose("Script engine " + engine.getClass().getName() + " does not implement Compilable", module);
}
}
if (script != null) {
@@ -177,11 +177,11 @@ public final class ScriptUtil {
Compilable compilableEngine = (Compilable) engine;
compiledScript = compilableEngine.compile(script);
if (Debug.verboseOn()) {
Debug.logVerbose("Compiled script [" + script + "] using engine " + engine.getClass().getName(), module);
if (Debug.verboseOn()) Debug.logVerbose("Compiled script [" + script + "] using engine " + engine.getClass().getName(), module);
}
} catch (ClassCastException e) {
if (Debug.verboseOn()) {
Debug.logVerbose("Script engine " + engine.getClass().getName() + " does not implement Compilable", module);
if (Debug.verboseOn()) Debug.logVerbose("Script engine " + engine.getClass().getName() + " does not implement Compilable", module);
}
}
if (compiledScript != null) {
@@ -273,7 +273,7 @@ public final class ScriptUtil {
throw new IllegalArgumentException("The script type is not supported for language: " + language);
}
if (Debug.verboseOn()) {
Debug.logVerbose("Begin processing script [" + script + "] using engine " + engine.getClass().getName(), module);
if (Debug.verboseOn()) Debug.logVerbose("Begin processing script [" + script + "] using engine " + engine.getClass().getName(), module);
}
ScriptContext scriptContext = createScriptContext(context);
return engine.eval(script, scriptContext);
@@ -298,7 +298,7 @@ public final class ScriptUtil {
Object result = script.eval(scriptContext);
if (UtilValidate.isNotEmpty(functionName)) {
if (Debug.verboseOn()) {
Debug.logVerbose("Invoking function/method " + functionName, module);
if (Debug.verboseOn()) Debug.logVerbose("Invoking function/method " + functionName, module);
}
ScriptEngine engine = script.getEngine();
try {
@@ -380,7 +380,7 @@ public final class ScriptUtil {
throw new IllegalArgumentException("The script type is not supported for location: " + filePath);
}
if (Debug.verboseOn()) {
Debug.logVerbose("Begin processing script [" + filePath + "] using engine " + engine.getClass().getName(), module);
if (Debug.verboseOn()) Debug.logVerbose("Begin processing script [" + filePath + "] using engine " + engine.getClass().getName(), module);
}
engine.setContext(scriptContext);
URL scriptUrl = FlexibleLocation.resolveLocation(filePath);
@@ -533,7 +533,7 @@ public class StringUtil {
result = pattern.matcher(result).replaceAll(entry.getKey());
}
if (Debug.verboseOn()) {
Debug.logVerbose("Converted " + expression + " to " + result, module);
if (Debug.verboseOn()) Debug.logVerbose("Converted " + expression + " to " + result, module);
}
}
return result;
@@ -159,7 +159,7 @@ public final class UtilHttp {
}
if (Debug.verboseOn()) {
Debug.logVerbose("Made Request Parameter Map with [" + paramMap.size() + "] Entries", module);
if (Debug.verboseOn()) Debug.logVerbose("Made Request Parameter Map with [" + paramMap.size() + "] Entries", module);
//Debug.logVerbose("Request Parameter Map Entries: " + System.getProperty("line.separator") + UtilMisc.printMap(paramMap), module); see OFBIZ-9310
}
@@ -319,8 +319,8 @@ public final class UtilHttp {
}
if (Debug.verboseOn()) {
Debug.logVerbose("Made Request Attribute Map with [" + attributeMap.size() + "] Entries", module);
Debug.logVerbose("Request Attribute Map Entries: " + System.getProperty("line.separator") + UtilMisc.printMap(attributeMap), module);
if (Debug.verboseOn()) Debug.logVerbose("Made Request Attribute Map with [" + attributeMap.size() + "] Entries", module);
if (Debug.verboseOn()) Debug.logVerbose("Request Attribute Map Entries: " + System.getProperty("line.separator") + UtilMisc.printMap(attributeMap), module);
}
return attributeMap;
@@ -354,8 +354,8 @@ public final class UtilHttp {
}
if (Debug.verboseOn()) {
Debug.logVerbose("Made Session Attribute Map with [" + sessionMap.size() + "] Entries", module);
Debug.logVerbose("Session Attribute Map Entries: " + System.getProperty("line.separator") + UtilMisc.printMap(sessionMap), module);
if (Debug.verboseOn()) Debug.logVerbose("Made Session Attribute Map with [" + sessionMap.size() + "] Entries", module);
if (Debug.verboseOn()) Debug.logVerbose("Session Attribute Map Entries: " + System.getProperty("line.separator") + UtilMisc.printMap(sessionMap), module);
}
return sessionMap;
@@ -389,8 +389,8 @@ public final class UtilHttp {
}
if (Debug.verboseOn()) {
Debug.logVerbose("Made ServletContext Attribute Map with [" + servletCtxMap.size() + "] Entries", module);
Debug.logVerbose("ServletContext Attribute Map Entries: " + System.getProperty("line.separator") + UtilMisc.printMap(servletCtxMap), module);
if (Debug.verboseOn()) Debug.logVerbose("Made ServletContext Attribute Map with [" + servletCtxMap.size() + "] Entries", module);
if (Debug.verboseOn()) Debug.logVerbose("ServletContext Attribute Map Entries: " + System.getProperty("line.separator") + UtilMisc.printMap(servletCtxMap), module);
}
return servletCtxMap;
@@ -76,7 +76,7 @@ public final class FlexibleMapAccessor<T> implements Serializable, IsEmpty {
this.isAscending = isAscending;
this.fse = fse;
if (Debug.verboseOn()) {
Debug.logVerbose("FlexibleMapAccessor created, original = " + this.original, module);
if (Debug.verboseOn()) Debug.logVerbose("FlexibleMapAccessor created, original = " + this.original, module);
}
}
@@ -149,7 +149,7 @@ public final class FlexibleMapAccessor<T> implements Serializable, IsEmpty {
} catch (PropertyNotFoundException e) {
// PropertyNotFound exceptions are common, so log verbose.
if (Debug.verboseOn()) {
Debug.logVerbose("UEL exception while getting value: " + e + ", original = " + this.original, module);
if (Debug.verboseOn()) Debug.logVerbose("UEL exception while getting value: " + e + ", original = " + this.original, module);
}
} catch (Exception e) {
Debug.logError("UEL exception while getting value: " + e + ", original = " + this.original, module);
@@ -602,7 +602,7 @@ public abstract class FlexibleStringExpander implements Serializable, IsEmpty {
}
} catch (PropertyNotFoundException e) {
if (Debug.verboseOn()) {
Debug.logVerbose("Error evaluating expression: " + e, module);
if (Debug.verboseOn()) Debug.logVerbose("Error evaluating expression: " + e, module);
}
} catch (Exception e) {
Debug.logError("Error evaluating expression: " + e, module);
@@ -656,7 +656,7 @@ public abstract class FlexibleStringExpander implements Serializable, IsEmpty {
return obj;
} else {
if (Debug.verboseOn()) {
Debug.logVerbose("Scriptlet evaluated to null [" + this + "].", module);
if (Debug.verboseOn()) Debug.logVerbose("Scriptlet evaluated to null [" + this + "].", module);
}
}
} catch (Exception e) {
@@ -691,7 +691,7 @@ public abstract class FlexibleStringExpander implements Serializable, IsEmpty {
return UelUtil.evaluate(context, openBracket.concat(expr.toString()).concat(closeBracket));
} catch (PropertyNotFoundException e) {
if (Debug.verboseOn()) {
Debug.logVerbose("Error evaluating expression: " + e, module);
if (Debug.verboseOn()) Debug.logVerbose("Error evaluating expression: " + e, module);
}
} catch (Exception e) {
Debug.logError("Error evaluating expression: " + e, module);
@@ -716,7 +716,7 @@ public abstract class FlexibleStringExpander implements Serializable, IsEmpty {
obj = UelUtil.evaluate(context, new String(this.bracketedOriginal));
} catch (PropertyNotFoundException e) {
if (Debug.verboseOn()) {
Debug.logVerbose("Error evaluating expression " + this + ": " + e, module);
if (Debug.verboseOn()) Debug.logVerbose("Error evaluating expression " + this + ": " + e, module);
}
} catch (Exception e) {
Debug.logError("Error evaluating expression " + this + ": " + e, module);
@@ -86,7 +86,7 @@ public class JuelConnector {
if (base == null) {
base = UelUtil.autoVivifyListOrMap(property);
if (Debug.verboseOn()) {
Debug.logVerbose("ExtendedAstBracket.setValue auto-vivify base: " + base + ", property = " + property, module);
if (Debug.verboseOn()) Debug.logVerbose("ExtendedAstBracket.setValue auto-vivify base: " + base + ", property = " + property, module);
}
prefix.setValue(bindings, context, base);
}
@@ -120,7 +120,7 @@ public class JuelConnector {
if (base == null) {
base = UelUtil.autoVivifyListOrMap(property);
if (Debug.verboseOn()) {
Debug.logVerbose("ExtendedAstDot.setValue auto-vivify base: " + base + ", property = " + property, module);
if (Debug.verboseOn()) Debug.logVerbose("ExtendedAstDot.setValue auto-vivify base: " + base + ", property = " + property, module);
}
prefix.setValue(bindings, context, base);
}
@@ -264,7 +264,7 @@ public class UelFunctions {
} catch (Exception e) {
Debug.logError(e, "Error while initializing UelFunctions.Functions instance", module);
}
Debug.logVerbose("UelFunctions.Functions loaded " + this.functionMap.size() + " functions", module);
if (Debug.verboseOn()) Debug.logVerbose("UelFunctions.Functions loaded " + this.functionMap.size() + " functions", module);
}
@Override
public Method resolveFunction(String prefix, String localName) {
@@ -97,7 +97,7 @@ public final class UelUtil {
*/
public static void setValue(Map<String, Object> context, String expression, Class expectedType, Object value) {
if (Debug.verboseOn()) {
Debug.logVerbose("UelUtil.setValue invoked, expression = " + expression + ", value = " + value, module);
if (Debug.verboseOn()) Debug.logVerbose("UelUtil.setValue invoked, expression = " + expression + ", value = " + value, module);
}
ELContext elContext = new BasicContext(context);
ValueExpression ve = exprFactory.createValueExpression(elContext, expression, expectedType);
@@ -111,7 +111,7 @@ public final class UelUtil {
*/
public static void removeValue(Map<String, Object> context, String expression) {
if (Debug.verboseOn()) {
Debug.logVerbose("UelUtil.removeValue invoked, expression = " + expression , module);
if (Debug.verboseOn()) Debug.logVerbose("UelUtil.removeValue invoked, expression = " + expression , module);
}
ELContext elContext = new BasicContext(context);
ValueExpression ve = exprFactory.createValueExpression(elContext, expression, Object.class);
@@ -340,7 +340,7 @@ public final class UelUtil {
super.setValue(context, base, property, val);
if (!context.isPropertyResolved() && base == null) {
if (Debug.verboseOn()) {
Debug.logVerbose("ExtendedCompositeResolver.setValue: base = " + base + ", property = " + property + ", value = " + val, module);
if (Debug.verboseOn()) Debug.logVerbose("ExtendedCompositeResolver.setValue: base = " + base + ", property = " + property + ", value = " + val, module);
}
try {
BasicContext elContext = (BasicContext) context;
@@ -375,14 +375,14 @@ public final class UelUtil {
String str = property.toString();
if ("add".equals(str)) {
if (Debug.verboseOn()) {
Debug.logVerbose("ExtendedListResolver.setValue adding List element: base = " + base + ", property = " + property + ", value = " + val, module);
if (Debug.verboseOn()) Debug.logVerbose("ExtendedListResolver.setValue adding List element: base = " + base + ", property = " + property + ", value = " + val, module);
}
context.setPropertyResolved(true);
List list = (List) base;
list.add(val);
} else if (str.startsWith("insert@")) {
if (Debug.verboseOn()) {
Debug.logVerbose("ExtendedListResolver.setValue inserting List element: base = " + base + ", property = " + property + ", value = " + val, module);
if (Debug.verboseOn()) Debug.logVerbose("ExtendedListResolver.setValue inserting List element: base = " + base + ", property = " + property + ", value = " + val, module);
}
context.setPropertyResolved(true);
String indexStr = str.replace("insert@", "");
@@ -436,7 +436,7 @@ public final class UelUtil {
}
if (locale == null) {
if (Debug.verboseOn()) {
Debug.logVerbose("ExtendedMapResolver.getValue: unable to find Locale for LocalizedMap element, using default locale", module);
if (Debug.verboseOn()) Debug.logVerbose("ExtendedMapResolver.getValue: unable to find Locale for LocalizedMap element, using default locale", module);
}
locale = Locale.getDefault();
}
@@ -144,7 +144,7 @@ public final class FreeMarkerWorker {
String key = (String) i.next();
String className = props.getProperty(key);
if (Debug.verboseOn()) {
Debug.logVerbose("Adding FTL Transform " + key + " with class " + className, module);
if (Debug.verboseOn()) Debug.logVerbose("Adding FTL Transform " + key + " with class " + className, module);
}
try {
config.setSharedVariable(key, loader.loadClass(className).newInstance());