How to avoid InvalidInputException stacktrace in log using custom Validators

Jozef Kotlár
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 8, 2012

This is actually documented in https://jira.atlassian.com/browse/JRA-8100

Problem: this exceptions is treated as a server error by JIRA and written in the log files and on the console!

Bad user input is not a server error, it is a normal use case...

I would like to know how to handle it best.

11 answers

1 accepted

4 votes
Answer accepted
Jozef Kotlár
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 12, 2012

Thanks to Jobin suggestion I am satisfied with following solution using configurable version of custom filter:

  1. copy jira-log4j-extras-1.1.jar to lib directory of JIRA installation (with at the least log4j-1.2.16.jar)
  2. filter out InvalidInputException in OSWorkflowManager from common appenders console and filelog with
    log4j.appender.console.filter.01=sk.eea.jira.log4j.filters.ValidatorExceptionFilter 
  3. (optionally) configure new appender only for those exceptions to keep track of them
    log4j.appender.validatorexlog=com.atlassian.jira.logging.MultiTenantJiraHomeAppender
    log4j.appender.validatorexlog.File=atlassian-jira-validator-exceptions.log
    log4j.appender.validatorexlog.MaxFileSize=20480KB
    log4j.appender.validatorexlog.MaxBackupIndex=5
    log4j.appender.validatorexlog.layout=org.apache.log4j.PatternLayout
    log4j.appender.validatorexlog.layout.ConversionPattern=%d %t %p %X{jira.username} %X{jira.request.id} %X{jira.request.assession.id} %X{jira.request.ipa
    log4j.appender.validatorexlog.filter.01=sk.eea.jira.log4j.filters.ValidatorExceptionFilter log4j.appender.validatorexlog.filter.01.AcceptOnMatch=true log4j.appender.validatorexlog.filter.99=org.apache.log4j.varia.DenyAllFilter log4j.logger.com.atlassian.jira.workflow.OSWorkflowManager=ERROR, validatorexlog
Brent Webster
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 6, 2013

Jozef: I copied your jar file into the lib directory:

/opt/atlassian/jira/lib/jira-log4j-extras-1.1.jar
/opt/atlassian/jira/lib/slf4j-log4j12-1.6.4.jar
/opt/atlassian/jira/lib/log4j-1.2.16.jar

And I restarted my 5.2.11 standalone jira server but got the following error in the catalina.out file:

INFO: Starting Servlet Engine: Apache Tomcat/7.0.29
log4j:ERROR Could not instantiate class [sk.eea.jira.log4j.filters.ValidatorExceptionFilter ].
java.lang.ClassNotFoundException: sk.eea.jira.log4j.filters.ValidatorExceptionFilter 
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
... remaining exception trace deleted for brevity

Note: Append the following text to log4j.properties:

############################################################
log4j.appender.console.filter.01=sk.eea.jira.log4j.filters.ValidatorExceptionFilter

So what did I do wrong?

Jozef Kotlár
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 7, 2013

Are you sure you removed log4j-1.2.15.jar?

Brent Webster
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 7, 2013

Yes, I used the command: "find /opt/atlassian/jira -name \*log4j\*" to determine that full list of three jar files.

0 votes
Claus April 8, 2013

Hi Jozef,

I have one Idea: Maybe it is not possible to use the filter on the default console appender?

The filter itself works on my selfdefined validatorexlog...

0 votes
Jozef Kotlár
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 8, 2013

Yes, I've read that article and there is stated, that it works in 1.2.16.

Well, I have checked back to the history of mercurial queue and found we were using it on JIRA 4.4.5 with replaced log4j in lib directory. I have no clue, why it not works for you.

0 votes
Claus April 7, 2013

I found an article where is statet that Filters cannot be defined in

http://stackoverflow.com/questions/3730343/log4j-stringtomatch-in-property-file

Strange stuff:

log4j.appender.console.filter.01=sk.eea.jira.log4j.filters.ValidatorExceptionFilter

wont work but
log4j.appender.validatorexlog.filter.01=sk.eea.jira.log4j.filters.ValidatorExceptionFilter
log4j.appender.validatorexlog.filter.01.AcceptOnMatch=true
log4j.appender.validatorexlog.filter.99=org.apache.log4j.varia.DenyAllFilter
does write data into this file...
Maybe while console logger is loaded, your jar file is not loaded?
0 votes
Claus April 7, 2013

I did copy both jars to Folder

/opt/atlassian/jira/lib/ as stated above (there was my old log4j file which I removed).

I also tried to put file here: /opt/atlassian/jira/atlassian-jira/WEB-INF/lib/jira-log4j-extras-1.1.jar

but it did not work - I get an error:

log4j:ERROR Could not instantiate class [sk.eea.jira.log4j.filters.ValidatorExceptionFilter ].
java.lang.ClassNotFoundException: sk.eea.jira.log4j.filters.ValidatorExceptionFilter
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)

Which shows me having a not loaded classfile.

Do I have to add this anywhere? Normally my Classloader should pick this anytime?

0 votes
eMundo GmbH Support Team April 7, 2013

Can I use log4j-1.2.16 in Jira 4.4.4 without any side effects?

Jozef Kotlár
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 7, 2013

This is not an asnwer, anyway you can - replace older version in JIRA instalation

Claus April 7, 2013

Sorry thanks!

0 votes
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 9, 2012

I see. The only issue with that is what Atlassian suggested in the ticket itself. Sometime the InvalidInputException is not genuine and you might want to log them. Wiping them completely out might hide some errors. But as long as you know your config, that must be okay.

0 votes
Jozef Kotlár
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 9, 2012
Have look at the code https://bitbucket.org/dodok1/jira-log4j-extras/src/4310dbe43731/src/main/java/sk/eea/jira/log4j/filters/ValidatorExceptionFilter.java To make it as effective as possible I check only ERROR from OSWorkflow starting with [InvalidInputException...
0 votes
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 8, 2012

What are you filtering here? All errors of type InvalidInputException? or all errors?

0 votes
Jozef Kotlár
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 8, 2012

Actually I came after some investiogation to solution that avoids the ERROR completely. Anyway, it would be nicer, to change the level into INFO and single line.

To filter out the logging event completely, you should

  • provide at least version 1.2.16 of log4j.jar (already available in JIRA 5) to enable filter configuration in properties
  • provide custom filter into lib directory along with log4j.jar as did I in https://bitbucket.org/dodok1/jira-log4j-extras/downloads/jira-log4j-extras-1.0.jar
  • add following line to WEB-INF/classes/log4j.properties
    log4j.appender.console.filter.01=sk.eea.jira.log4j.filters.ValidatorExceptionFilter

0 votes
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 8, 2012

Yeah, it is a pain but I haven't come across a way to handle it!

Suggest an answer

Log in or Sign up to answer