• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

ServletContext.setInitParameter does not throw IllegalStateException

 
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.
Considering Oracle's documentation for ServletContext.setInitParameter method, there is the following assertion when describing the exceptions that could be thrown when setInitParameter is invoked:

IllegalStateException - if this ServletContext has already been initialized



To test this, I've created a context parameter at DD (Web Deployment Descriptor - which should be initialized when the application is started) .
So I've tried to change the attribute value expecting for an exception (IllegalStateException in such case).

I'd like to know why this exception isn't thrown?

Context parameter defined at DD:


And the servlet's code that tries to change the context parameter through setInitParameter.


Thanks in advance.
 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Adolfo.

you have misinterpreted the documenation. the docs say that the IllegalStateException occurs when the ServletContext has already been initialized. it DOES NOT say that if you try to override the context parameters. setting the parameters and initialization of ServletContext are 2 different things, although when ServletContext is initiazlized(at deployment time) it is given references to context parameters name/value pairs but they ain't the same.

Regarding your second query the doc say that setInitParameter will return false if you try to set a parameter whose value is already set earlier. so in your case the name/value pairs will not be changed by the method call.

Regards
Gurpreet
 
Creator of Enthuware JWS+ V6
Posts: 3398
312
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason why this IllegalStateException can be thrown is explained in this thread.

Regards,
Frits
 
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic