From 81a3776a3c17659dcf934a2d02b26495633ab96c Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Sat, 7 Sep 2024 07:02:26 +0200 Subject: [PATCH] WW-5458 Replaces e.printStackTrace() with proper logger --- .../xwork2/mock/MockObjectTypeDeterminer.java | 9 ++++++--- .../com/opensymphony/xwork2/util/ClassPathFinder.java | 6 +++++- .../com/opensymphony/xwork2/util/PropertiesReader.java | 8 +++++++- .../interceptor/debugging/DebuggingInterceptor.java | 4 ++-- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/mock/MockObjectTypeDeterminer.java b/core/src/main/java/com/opensymphony/xwork2/mock/MockObjectTypeDeterminer.java index 40e633aae8..4c8eef88d2 100644 --- a/core/src/main/java/com/opensymphony/xwork2/mock/MockObjectTypeDeterminer.java +++ b/core/src/main/java/com/opensymphony/xwork2/mock/MockObjectTypeDeterminer.java @@ -21,6 +21,8 @@ import com.opensymphony.xwork2.conversion.ObjectTypeDeterminer; import ognl.OgnlException; import ognl.OgnlRuntime; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Map; @@ -31,6 +33,8 @@ */ public class MockObjectTypeDeterminer implements ObjectTypeDeterminer { + private static final Logger LOG = LogManager.getLogger(MockObjectTypeDeterminer.class); + private Class keyClass; private Class elementClass; private String keyProperty; @@ -69,10 +73,9 @@ public String getKeyProperty(Class parentClass, String property) { public boolean shouldCreateIfNew(Class parentClass, String property, Object target, String keyProperty, boolean isIndexAccessed) { try { - System.out.println("ognl:"+OgnlRuntime.getPropertyAccessor(Map.class)+" this:"+this); + LOG.info("Ognl: {} this: {}", OgnlRuntime.getPropertyAccessor(Map.class), this); } catch (OgnlException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOG.error("Call to shouldCreateIfNew has failed!", e); } return isShouldCreateIfNew(); } diff --git a/core/src/main/java/com/opensymphony/xwork2/util/ClassPathFinder.java b/core/src/main/java/com/opensymphony/xwork2/util/ClassPathFinder.java index 7a23791105..1b97bf517c 100644 --- a/core/src/main/java/com/opensymphony/xwork2/util/ClassPathFinder.java +++ b/core/src/main/java/com/opensymphony/xwork2/util/ClassPathFinder.java @@ -18,6 +18,8 @@ */ package com.opensymphony.xwork2.util; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.struts2.StrutsException; import java.io.File; @@ -41,6 +43,8 @@ */ public class ClassPathFinder { + private static final Logger LOG = LogManager.getLogger(ClassPathFinder.class); + /** * The String pattern to test against. */ @@ -106,7 +110,7 @@ public Vector findMatches() { } } } catch (IOException e) { - e.printStackTrace(); + LOG.warn("Error reading zip file: {}", entry, e); } } else { Vector results = checkEntries(entry.list(), entry, ""); diff --git a/core/src/main/java/com/opensymphony/xwork2/util/PropertiesReader.java b/core/src/main/java/com/opensymphony/xwork2/util/PropertiesReader.java index 62319f0f2c..bc1ef413f9 100644 --- a/core/src/main/java/com/opensymphony/xwork2/util/PropertiesReader.java +++ b/core/src/main/java/com/opensymphony/xwork2/util/PropertiesReader.java @@ -18,6 +18,9 @@ */ package com.opensymphony.xwork2.util; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + import java.io.IOException; import java.io.LineNumberReader; import java.io.Reader; @@ -40,6 +43,9 @@ *

*/ public class PropertiesReader extends LineNumberReader { + + private static final Logger LOG = LogManager.getLogger(PropertiesReader.class); + /** * Stores the comment lines for the currently processed property. */ @@ -451,7 +457,7 @@ public static String unescapeJava(String str) { return writer.toString(); } catch (IOException ioe) { // this should never ever happen while writing to a StringWriter - ioe.printStackTrace(); + LOG.warn("Call to unescape java string failed!", ioe); return null; } } diff --git a/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java index bf8fabe69d..f51eb18230 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java @@ -203,7 +203,7 @@ public String intercept(ActionInvocation inv) throws Exception { ServletActionContext.getResponse().getWriter()) { writer.print(stack.findValue(cmd)); } catch (IOException ex) { - ex.printStackTrace(); + LOG.warn("Interceptor in: {} mode has failed!", COMMAND_MODE, ex); } cont = false; } else if (BROWSER_MODE.equals(type)) { @@ -286,7 +286,7 @@ protected void printContext() { printContext(writer); writer.close(); } catch (IOException ex) { - ex.printStackTrace(); + LOG.warn("Call to PrettyPrintWriter failed!", ex); } }