Home  >  Forum  >  Core Java
Post New Query

java.lang.IllegalArgumentException with URLDecoder.decode() for %


joined on
April 01,2014
Asked on July 23,2014
Hi,
I am using URLDecoder.decode() in my web application. When this methods get % in parameter value,
it throws java.lang.IllegalArgumentException.

How to handle this exception.
joined on
March 14,2013
Replied on July 24,2014

Check the below Java doc of URLDecoder.decode()
It does not accept "%x" it means it can not accept values as "%" or "%abcd".
To handle the IllegalArgumentException, we need to check for such condition.

// A trailing, incomplete byte encoding such as
                    // "%x" will cause an exception to be thrown


        if ((i < numChars) && (c=='%'))
                        throw new IllegalArgumentException(
                         "URLDecoder: Incomplete trailing escape (%) pattern");

When we send data from browser to server, browser does one time encoding
and request.getParameter() does one time decoding and if output of 
request.getParameter() is passed to URLDecoder.decode(), then "%x" values will throw
IllegalArgumentException

Write Answer









Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us