Saturday, July 11, 2009

Code Inspection for Bug 245698

In the past two weeks, to locate the code which causes the bug, I have checked out org.eclipse.wst.sse.core, org.eclipse.wst.xml.core, org.eclipse.wst.sse.ui, and org.eclipse.wst.xml.ui. I started with searching for the radio button label "Create XML file from an XML schema file" in new XML wizard. Then I found out the source code for creating a New XML schema Wizard window in org.eclipse.wst.xml.ui - NewXMLWizard.java.
In NewXMLWizard.java, there is a fuction called perfromFinish(), and here is its signature public boolean performFinish(). Within the function is the code doing the background processes when the "Finish" button on the New XML Wizard is clicked. In performFinish(), I found the following code handling the creation of a new xml document.

if (getContainer().getCurrentPage() == selectRootElementPage) {
generator.createXMLDocument(newFile, xmlFileName);
}
else {
// put template contents into file
String templateString = fNewXMLTemplatesWizardPage.getTemplateString();
generator.createTemplateXMLDocument(newFile, templateString);
}

So, I inserted a break point in the first line of the above code, debugged eclipse-wtp, and reproduced the bug. When the break point was hit, it met the codition in the if statement, and called createXMLDocument(). Then I looked up the type of generator, and found the type of it is NewXMLGenerator. NewXMLGenerator.java is in also in org.eclipse.wst.xml.ui. Then, I checked out createXMLDocument() in org.eclipse.wst.xml.ui. createXMLDocument is overloaded with three different signatures. The one called from NewXMLWizard.java is public ByteArrayOutputStream createXMLDocument(String xmlFileName, String charset) throws Exception. Basically, the createXMLDocument() is responsible for creating the XML document from the XML schema and then put the content of the newly created XML document into a file named by the user with an output stream, The following line in createXMLDocument is doing the job of creating a new XML document based on a XML schema.

DOMContentBuilderImpl contentBuilder = new DOMContentBuilderImpl(xmlDocument);

So, in the following week, I will look more into DOMContentBuilderImpl...

Saturday, July 4, 2009

Cause of Eclipse WTP Bug #245698

After I reproduced the bug successfully, I started to look into the reason why the newly created XML file did not pass the validation. Here is a screen shot of the XML file generated from web-jsptaglibrary_2_1.xsd:



In the screen shot, notice that there are 26 errors in the XML file, and the major one is "cvc-complex-type.3.2.2: Attribute 'javaee:lang' is not allowed to appear in element 'javaee:description'", which applied to all <javaee:description>, <javaee:display-name>, and <javaee:icon tags in the XML file>.

What this error mean is javaee:lang is not a valid attribute inside <javaee:description>, <javaee:display-name>, and <javeee:icon>. So, I checked out the XML schema definition file web-jsptaglibrary_2_1.xsd.

Lines in between <xsd:complexType name="tldTagLibType"\> and its corresponding </xsd:complexType> is the type definition for tldTagLibType - type of taglib. Those lines are saying taglib can the following child tags in sequence: description(optional), display-name, icon(optional), tlib-version, short-name, uri, validator, listener(optional), tag(optional), tag-file, function, and tablib-extension. And also, description, display-name, and icon are grouped together and defined as "descriptionGroup".

So, to check out the definition for <javaee:description>, <javaee:display-name>, and <javaee:icon>, I first found XML schema definition file in which "descriptionGroup" is defined, and it is javaee_5.xsd. Surprisingly, the definition of descriptionGroup, description, display-name, and icon are all in javaee_5.xsd.

descriptionGroup:


descriptionType:


After checking out the definition for descriptionType, I found out that the correct prefix for lang attribute inside <javaee:description> should be xml, rather that javaee, which is also true to <javaee:display-name> and <javaee:icon>.

Then, I tried to changed all javaee:lang inside <javaee:description>, <javaee:display-name>, and <javaee:icon> of the XML file generated from web-jsptaglibrary_2_1.xsd to xml:lang. Compared to the previous screen shot on the newly created XML file. All "cvc-complex-type.3.2.2: Attribute 'javaee:lang' is not allowed to appear in element 'javaee:description'" are gone.



So, the cause of this bug is the prefix for the lang attribute inside <javaee:description>, <javaee:display-name>, and <javaee:icon> is not configured correctly.

Thursday, July 2, 2009

Solution to "java.lang.OutOfMemoryError: PermGen space"

I was trying to debug Eclipse WTP with Eclipse for RCP to locate the code causing the bug I mentioned in the previous post. When the break point inserted was hit, it returned such as error "java.lang.OutOfMemoryError: PermGen space" in the console window of Eclipse for RCP.

I googled the error message for solutions, and find the following link, http://www.freshblurbs.com/explaining-java-lang-outofmemoryerror-permgen-space, has a detailed explanation on what exactly this error is and the cause of the error.

The easiest way to solve this problem is to increase the maximum size of PermGen space. You can change the size of PermGen space by either editing eclipse.ini of Eclipse Web Tools Platform or specifying the JVM memory settings of Eclipse for RCP.

To change the maximum size of PermGen space through eclipse.ini of Eclipse Web Tools Platform, navigate to the folder where WTP is installed. Then you will find a file called "eclipse.ini" similar to this:



What you need to do is to add the following line to the end of the file:
-XX:MaxPermSize=128m (not necessarily 128m, default is 64m)

To change the maximum size of PermGen space on Eclipse memory settings of JVM, Click on Run/Debug Configurations... under Run menu. Then the Run/Debug Configurations... window pops up. On the left panel of Run/Debug Configurations... window, expand "Eclipse Application" and select new configuration. (If you do not see any configuration, create a new one by right clicking on "Eclipse Application" and select "New" from the context menu). On the right panel of Run/Debug Configurations... window, click on the argument tab, put the following line into the text box for "VMarguments":
-XX:MaxPermSize=128m

Click on Run/Debug at the bottom.