Skip to content

Commit 3fb1d50

Browse files
committed
Improved: Use method references instead of lambda inside variables
(OFBIZ-10817) Lambda expressions are not meant to be stored inside variables. In most cases it is better to define a static method and use a method reference instead. Static methods have the benefits of having a more explicit signature and some javadoc attached to them. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1864953 13f79535-47bb-0310-9956-ffa450edef68
1 parent 7c8f7a5 commit 3fb1d50

File tree

1 file changed

+40
-29
lines changed

1 file changed

+40
-29
lines changed

framework/base/src/main/java/org/apache/ofbiz/base/util/template/FreeMarkerWorker.java

+40-29
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ public static Configuration makeConfiguration(BeansWrapper wrapper) {
112112
boolean verboseTemplate = ModelWidget.widgetBoundaryCommentsEnabled(null)
113113
|| UtilProperties.getPropertyAsBoolean("widget", "widget.freemarker.template.verbose", false);
114114
newConfig.setTemplateExceptionHandler(verboseTemplate
115-
? OFBizTemplateExceptionHandler.OFBIZ_DEBUG_HANDLER
116-
: OFBizTemplateExceptionHandler.OFBIZ_DEFAULT_HANDLER);
115+
? FreeMarkerWorker::handleTemplateExceptionVerbosily
116+
: FreeMarkerWorker::handleTemplateException);
117117
try {
118118
newConfig.setSetting("datetime_format", "yyyy-MM-dd HH:mm:ss.SSS");
119119
newConfig.setSetting("number_format", "0.##########");
@@ -498,34 +498,45 @@ protected URL getURL(String name) {
498498
}
499499

500500
/**
501-
* OFBiz specific {@link TemplateExceptionHandler} interface.
501+
* Handles template exceptions quietly.
502+
* <p>
503+
* This is done by suppressing the exception and replacing it by a generic char for quiet alert.
504+
* Note that exception is still logged.
505+
* <p>
506+
* This implements the {@link TemplateExceptionHandler} functional interface.
507+
*
508+
* @param te the exception that occurred
509+
* @param env the runtime environment of the template
510+
* @param out this is where the output of the template is written
502511
*/
503-
interface OFBizTemplateExceptionHandler {
504-
505-
/**
506-
* {@link TemplateExceptionHandler} that suppresses the exception and keep the rendering going on.
507-
* It sanitizes any messages present in the stack trace prior to printing to the output writer.
508-
*/
509-
TemplateExceptionHandler OFBIZ_DEBUG_HANDLER = (te, env, out) -> {
510-
try {
511-
out.write(te.getMessage());
512-
Debug.logError(te, module);
513-
} catch (IOException e) {
514-
Debug.logError(e, module);
515-
}
516-
};
512+
private static void handleTemplateException(TemplateException te, Environment env, Writer out) {
513+
try {
514+
out.write(UtilProperties.getPropertyValue("widget", "widget.freemarker.template.exception.message", "∎"));
515+
Debug.logError(te, module);
516+
} catch (IOException e) {
517+
Debug.logError(e, module);
518+
}
519+
}
517520

518-
/**
519-
* {@link TemplateExceptionHandler} that suppresses the exception and replace by a generic char for quiet alert.
520-
* As mentioned in the doc, the stack trace is still logged {@link TemplateExceptionHandler#IGNORE_HANDLER}
521-
*/
522-
TemplateExceptionHandler OFBIZ_DEFAULT_HANDLER = (te, env, out) -> {
523-
try {
524-
out.write(UtilProperties.getPropertyValue("widget", "widget.freemarker.template.exception.message","∎"));
525-
Debug.logError(te, module);
526-
} catch (IOException e) {
527-
Debug.logError(e, module);
528-
}
529-
};
521+
/**
522+
* Handles template exceptions verbosely.
523+
* <p>
524+
* This is done by suppressing the exception and keeping the rendering going on. Messages
525+
* present in the stack trace are sanitized before printing them to the output writer.
526+
* Note that exception is still logged.
527+
* <p>
528+
* This implements the {@link TemplateExceptionHandler} functional interface.
529+
*
530+
* @param te the exception that occurred
531+
* @param env the runtime environment of the template
532+
* @param out this is where the output of the template is written
533+
*/
534+
private static void handleTemplateExceptionVerbosily(TemplateException te, Environment env, Writer out) {
535+
try {
536+
out.write(te.getMessage());
537+
Debug.logError(te, module);
538+
} catch (IOException e) {
539+
Debug.logError(e, module);
540+
}
530541
}
531542
}

0 commit comments

Comments
 (0)