Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 316102

Summary: getDeploymentDescriptorRoot() throws IndexOutOfBoundsException and version is not set in org.eclipse.jst.j2ee.web.componentcore.util.WebArtifactEdit.addWebAppIfNecessary
Product: [WebTools] WTP Java EE Tools Reporter: Badri <baravich>
Component: jst.j2eeAssignee: Hari Shankar <hshanka>
Status: CLOSED INVALID QA Contact: Chuck Bridgham <cbridgha>
Severity: normal    
Priority: P3 CC: ccc
Version: 3.2   
Target Milestone: 3.2.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Badri CLA 2010-06-08 04:41:24 EDT
Build Identifier: 

There are two issues.
1)Using an object of WebArtifactEdit, getWebApp() method is called.This internally calls org.eclipse.jst.j2ee.web.componentcore.util.WebArtifactEdit.getDeploymentDescriptorRoot().Here getDeploymentDescriptorResource().getContents() is called and if no contents exist,addWebAppIfNecessary is called to create a web.xml file. 

Then contents.get(0) is directly returned which throws an IndexOutOfBoundsException if no contents exist.A check has to be added like
return contents.size() > 0?(EObject) contents.get(0):null; to prevent this.

2)Assuming that 1) is fixed,there is another issue of web-app version not getting added in web.xml.
The scenario is that web.xml doesn't exist in the project and WebArtifactEdit.getWebApp() is called.As discussed in 1), addWebAppIfNecessary is called to create a web.xml file.The function internally stores the webapp id,creates the list of welcome files.It also sets the version of webapp(through a notification in aResource.getContents().add(webAppNew);) based on module version id.But it finally creates a web.xml file with just a line(<?xml version="1.0" encoding="UTF-8"?>) and saves it.

Another call to WebArtifactEdit.getWebApp() again sets the webappid and the list of welcome files, but it doesn't set the version of the webapp(no notification in aResource.getContents().add(webAppNew) comes to set it).The web.xml is updated with the other contents like welcome files,webapp tag etc.,but version is not set which is flagged as an XML Problem.The version of the web-app has to be set in the web.xml file.

Reproducible: Always
Comment 1 Badri CLA 2010-06-08 04:44:41 EDT
Found in org.eclipse.jst.j2ee.web v201004190850
Comment 2 Carl Anderson CLA 2010-06-08 09:54:35 EDT
Badri,  looking at the version id you provided for the plugin, I assume that you are using Helios, which corresponds to WTP 3.2.  If this is not correct, please let us know.
Comment 3 Badri CLA 2010-06-09 02:22:04 EDT
(In reply to comment #0)

Also found that as a part of issue 2), the xsi:schemaLocation in the web.xml is always http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd inspite of selecting Dynamic web module version as something else.
Comment 4 Carl Anderson CLA 2010-06-09 08:46:30 EDT
Assigning to Hari for initial investigation.
Comment 5 Carl Anderson CLA 2010-07-07 16:52:46 EDT
The problem here is that calls to WebArtifactEdit for Web 3.0 projects without a deployment descriptor result in a Servlet 2.4 web.xml being created.  WebArtifactEdit is coded for Servlet 2.1 to 2.4 support, and can somewhat tolerate 2.5 and 3.0, however, it is not the correct way to access the Web 2.5 and Web 3.0 models and can result in undesireable side effects, such as the creation of a Servlet 2.4 web.xml.