You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2012/05/24 11:50:40 UTC

svn commit: r1342182 - /myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/DebugResponseWriterWrapper.java

Author: lofwyr
Date: Thu May 24 09:50:39 2012
New Revision: 1342182

URL: http://svn.apache.org/viewvc?rev=1342182&view=rev
Log:
Logging: Print a stack trace, if the closing tag name is not the estimated.
(This error is rare but important to see)

Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/DebugResponseWriterWrapper.java

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/DebugResponseWriterWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/DebugResponseWriterWrapper.java?rev=1342182&r1=1342181&r2=1342182&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/DebugResponseWriterWrapper.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/webapp/DebugResponseWriterWrapper.java Thu May 24 09:50:39 2012
@@ -51,10 +51,8 @@ public class DebugResponseWriterWrapper 
   public void writeComment(Object comment) throws IOException {
     String commentStr = comment.toString();
     if (commentStr.indexOf("--") > 0) {
-      String trace = getCallingClassStackTraceElementString();
-      LOG.error(
-          "Comment must not contain the sequence '--', comment = '"
-              + comment + "' " + trace.substring(trace.indexOf('(')));
+      LOG.error("Comment must not contain the sequence '--', comment = '" + comment + "'.",
+          new IllegalArgumentException());
 
       commentStr = StringUtils.replace(commentStr, "--", "++");
     }
@@ -131,41 +129,31 @@ public class DebugResponseWriterWrapper 
   }
 
   @Override
+  public void startElement(String name, UIComponent currentComponent)
+      throws IOException {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("start element: '" + name + "'");
+    }
+    stack.push(name);
+    responseWriter.startElement(name, currentComponent);
+  }
+
+  @Override
   public void endElement(String name) throws IOException {
     if (LOG.isDebugEnabled()) {
-      LOG.debug("end Element: " + name);
+      LOG.debug("end element: '" + name + "'");
     }
     String top = "";
     try {
       top = stack.pop();
     } catch (EmptyStackException e) {
-      LOG.error("Failed to close element \"" + name + "\"!");
-      throw e;
+      LOG.error("Failed to close element \"" + name + "\"!", e);
     }
 
     if (!top.equals(name)) {
-      final String trace = getCallingClassStackTraceElementString();
-      LOG.error("Element end with name='" + name + "' doesn't "
-          + "match with top element on the stack='" + top + "' "
-          + trace.substring(trace.indexOf('(')));
+      LOG.error("Element end with name='" + name + "' doesn't match with top element on the stack='" + top + "'.",
+          new IllegalArgumentException());
     }
     responseWriter.endElement(name);
   }
-
-  @Override
-  public void startElement(String name, UIComponent currentComponent)
-      throws IOException {
-    stack.push(name);
-    responseWriter.startElement(name, currentComponent);
-  }
-  
-  protected final String getCallingClassStackTraceElementString() {
-    final StackTraceElement[] stackTrace = new Exception().getStackTrace();
-    int i = 1;
-    while (stackTrace[i].getClassName().equals(this.getClass().getName())) {
-      i++;
-    }
-    return stackTrace[i].toString();
-  }
-
 }