diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/TreeWalker.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/TreeWalker.java index 7cb84c223..75b0905f9 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/TreeWalker.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/TreeWalker.java @@ -215,6 +215,8 @@ public final class TreeWalker walk(rootAST, contents); } catch (FileNotFoundException fnfe) { + Utils.getExceptionLogger() + .debug("FileNotFoundException occured.", fnfe); getMessageCollector().add( new LocalizedMessage( 0, @@ -224,6 +226,7 @@ public final class TreeWalker this.getClass())); } catch (IOException ioe) { + Utils.getExceptionLogger().debug("IOException occured.", ioe); getMessageCollector().add( new LocalizedMessage( 0, @@ -233,6 +236,8 @@ public final class TreeWalker this.getClass())); } catch (RecognitionException re) { + Utils.getExceptionLogger() + .debug("RecognitionException occured.", re); getMessageCollector().add( new LocalizedMessage( 0, @@ -242,6 +247,8 @@ public final class TreeWalker this.getClass())); } catch (TokenStreamException te) { + Utils.getExceptionLogger() + .debug("TokenStreamException occured.", te); getMessageCollector().add( new LocalizedMessage( 0, @@ -251,6 +258,7 @@ public final class TreeWalker this.getClass())); } catch (Throwable err) { + Utils.getExceptionLogger().debug("Throwable occured.", err); getMessageCollector().add( new LocalizedMessage( 0, diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/Utils.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/Utils.java index 6de3ad60c..f240f72c9 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/Utils.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/Utils.java @@ -30,6 +30,9 @@ import org.apache.commons.beanutils.ConversionException; import org.apache.regexp.RE; import org.apache.regexp.RESyntaxException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + /** * Contains utility methods. * @@ -40,6 +43,9 @@ public final class Utils { /** Map of all created regular expressions **/ private static final Map CREATED_RES = new HashMap(); + /** Shared instance of logger for exception logging. */ + private static final Log EXCEPTION_LOG = + LogFactory.getLog("com.puppycrawl.tools.checkstyle.ExceptionLog"); ///CLOVER:OFF /** stop instances being created **/ @@ -48,6 +54,17 @@ public final class Utils } ///CLOVER:ON + /** + * Accessor for shared instance of logger which should be + * used to log all exceptions occured during FileSetCheck + * work (debug() should be used). + * @return shared exception logger. + */ + public static Log getExceptionLogger() + { + return EXCEPTION_LOG; + } + /** * Returns whether the specified string contains only whitespace up to the * specified index. diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/NewlineAtEndOfFileCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/NewlineAtEndOfFileCheck.java index 301218ba3..2d338f33a 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/NewlineAtEndOfFileCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/NewlineAtEndOfFileCheck.java @@ -27,6 +27,7 @@ import com.puppycrawl.tools.checkstyle.Defn; import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck; import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; import com.puppycrawl.tools.checkstyle.api.MessageDispatcher; +import com.puppycrawl.tools.checkstyle.api.Utils; import org.apache.commons.beanutils.ConversionException; /** @@ -166,6 +167,7 @@ public class NewlineAtEndOfFileCheck args, this.getClass()); getMessageCollector().add(message); + Utils.getExceptionLogger().debug("IOException occured.", aEx); } ///CLOVER:ON } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/TranslationCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/TranslationCheck.java index 12934c352..49f7c2c2b 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/TranslationCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/TranslationCheck.java @@ -35,6 +35,7 @@ import com.puppycrawl.tools.checkstyle.Defn; import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck; import com.puppycrawl.tools.checkstyle.api.LocalizedMessage; import com.puppycrawl.tools.checkstyle.api.MessageDispatcher; +import com.puppycrawl.tools.checkstyle.api.Utils; /** *

@@ -166,6 +167,7 @@ public class TranslationCheck this.getClass()); final LocalizedMessage[] messages = new LocalizedMessage[] {message}; getMessageDispatcher().fireErrors(aFile.getPath(), messages); + Utils.getExceptionLogger().debug("IOException occured.", aEx); } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/usage/AbstractUsageCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/usage/AbstractUsageCheck.java index ec1aaa375..2edbfabfb 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/usage/AbstractUsageCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/usage/AbstractUsageCheck.java @@ -127,6 +127,7 @@ public abstract class AbstractUsageCheck public void logError(Exception aException) { log(0, "general.exception", new String[] {aException.getMessage()}); + Utils.getExceptionLogger().debug("An exception occured.", aException); } /**