Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

sendRedirect() with invalid URI  RSS feed

 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,
I read the following text in a book.
An IllegalArgumentException is thrown when the relative URL cannot be converted to a valid URL.


Just to test this, I did the following from a doGet() method:
response.sendRedirect("/nosuchresource");
But, I get to see a 404, no IllegalArgumentException.

Is the above statement incorrect?

Thanks,
Reema
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're misunderstanding the meaning of "converting to a valid URL".
The thing is, sendRedirect will try to make an instance of the java.net.URL (or one of its friends), using the String parameter you're passing. It's not going to check if the url exist, but if it's grammatically valid. In other words, if URL throws a MalformedURLException, sendRequest will throw the desired IllegalArgumentException.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doc says: "Thrown to indicate that a method has been passed an illegal or inappropriate argument."

I doubted. The book would have been, likely, stated this in order to relate it to some particular context/problem previously discussed on former pages.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition, response.sendRedirect() would never ever throw an IllegalArgumentException because it is not defined to do so.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
response.sendRedirect() would never ever throw an IllegalArgumentException because it is not defined to do so.

Well spotted !
 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks rachers!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!