jakartaee / servlet

Jakarta Servlet
https://eclipse.org/ee4j/servlet
Other
270 stars 87 forks source link

Clarify instantiation of a Servlet #128

Open glassfishrobot opened 9 years ago

glassfishrobot commented 9 years ago

Section 2.3.1 of the specification (Servlet 3.1 Final Release for Evaluation) merely says: "After loading the Servlet class, the container instantiates it for use."

I would like this to be clarified by including the constructor requirements & what happens if these requirements aren't met. For example:

After loading the Servlet class, the container instantiates it for use by invoking the no-args constructor (which may be private). If no such constructor is available, a ServletException is thrown.

glassfishrobot commented 6 years ago
glassfishrobot commented 9 years ago

@glassfishrobot Commented Reported by anthony_ve

glassfishrobot commented 8 years ago

@glassfishrobot Commented stuartdouglas said: I don't think this needs to be specified. If CDI is enabled the container can create the Servlet even if it does not have a default constructor via constructor injection.

glassfishrobot commented 8 years ago

@glassfishrobot Commented anthony_ve said: Good point about the constructor's signature, I hadn't considered CDI at the time. However, I believe it's needed to specify error conditions and exceptions, analog to what is already specified for initialization (2.3.2.1) and request handling (2.3.3.2). For example, is a container allowed to attempt instantiation again when a previous attempt failed? And if so, what happens if the constructor throws an UnavailableException? Is it treated the same way as during initialization, or is it treated just as any other kind of failure?

Here's a proposed text - adapted from 2.3.2.1 - for instantiation:

After loading the Servlet class, the container instantiates it for use. If instantiation fails, the container throws a ServletException.

A new instance may be instantiated by the container after a failed instantiation. The exception to this rule is when an UnavailableException (thrown by the servlet's constructor) indicates a minimum time of unavailability, and the container must wait for the period to pass before creating a new servlet instance.

glassfishrobot commented 8 years ago

@glassfishrobot Commented pbenedict said: Even if the constructor completes normally, the specification leaves undefined the kind of exception thrown if CDI cannot complete injection. Is it a regular ServletException so the container can instantiate again or is it UnavailableException because failed injection is likely a fatal error?

glassfishrobot commented 8 years ago

@glassfishrobot Commented markt_asf said: I'd lean towards any instantiation failure being treated as permanent unless it is an UnavailableException with a specific time frame in which case that should be used.

glassfishrobot commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA SERVLET_SPEC-128