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

Bug 324612

Summary: BIRT report engine throw "java.lang.ClassCastException" exception when html content in report contains comment node
Product: z_Archived Reporter: Alex Chen <xiaodic>
Component: BIRTAssignee: Birt-ReportEngine-inbox <Birt-ReportEngine-inbox>
Status: NEW --- QA Contact: Xiaoying Gu <bluesoldier>
Severity: major    
Priority: P3 CC: bluesoldier, thatnitind
Version: 2.5.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
The log file during generating pdf/word report none

Description Alex Chen CLA 2010-09-06 22:54:15 EDT
Build Identifier: 2.5.2

Our report contains html contents, which contains comment node, when I use BIRT report engine API to generate pdf/word document, BIRT will throw java.lang.ClassCastException like below.

Actually, the same code works well in Eclipse 3.3.2, which use org.eclipse.birt.report.engine_2.2.2.r22x_v20080107.jar, but it failed in BIRT 2.5.2 release.

By checking CVS of BIRT, this change has been imported during: http://dev.eclipse.org/viewcvs/index.cgi/source/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/layout/pdf/util/TableProcessor.java?root=BIRT_Project&r1=1.5&r2=1.6

A new method processCellStyle has been added, but didn't check the class type before do casting.

Code: org.eclipse.birt.report.engine.layout.pdf.util.TableProcessor.TableState.processCellStyle(Element, Map<Element, StyleProperties>)
///////////////////
private void processCellStyle( Element element,
				Map<Element, StyleProperties> cssStyles )
		{
			String border = element.getAttribute( PROPERTY_BORDER );
			String padding = element.getAttribute( PROPERTY_CELLPADDING );
			boolean hasBorder = border != null && border.length( ) > 0;
			boolean hasPadding = padding != null && padding.length( ) > 0;
			if ( hasBorder || hasPadding )
			{
				for ( Node node = element.getFirstChild( ); node != null; node = node
						.getNextSibling( ) )
				{
					Element r = (Element) node;
					if ( TAG_TR.equals( r.getTagName( ) ) )
					{
						processRow( r, cssStyles, border, padding )
///////////////////



Exception:
//////////////////
Throwable occurred: java.lang.ClassCastException: org.apache.xerces.dom.CommentImpl incompatible with org.w3c.dom.Element
	at org.eclipse.birt.report.engine.layout.pdf.util.TableProcessor$TableState.processCellStyle(TableProcessor.java:214)
	at org.eclipse.birt.report.engine.layout.pdf.util.TableProcessor$TableState.<init>(TableProcessor.java:166)
	at org.eclipse.birt.report.engine.layout.pdf.util.TableProcessor.processTable(TableProcessor.java:50)
	at org.eclipse.birt.report.engine.layout.pdf.util.HTML2Content.handleElement(HTML2Content.java:692)
	at org.eclipse.birt.report.engine.layout.pdf.util.HTML2Content.processNodes(HTML2Content.java:538)
	at org.eclipse.birt.report.engine.layout.pdf.util.HTML2Content.handleElement(HTML2Content.java:702)
	at org.eclipse.birt.report.engine.layout.pdf.util.HTML2Content.processNodes(HTML2Content.java:538)
	at org.eclipse.birt.report.engine.layout.pdf.util.HTML2Content.processForeignData(HTML2Content.java:467)
	at org.eclipse.birt.report.engine.layout.pdf.util.HTML2Content.html2Content(HTML2Content.java:418)
	at org.eclipse.birt.report.engine.nLayout.LayoutEngine.startForeign(LayoutEngine.java:668)
	at org.eclipse.birt.report.engine.emitter.ContentEmitterUtil.startContent(ContentEmitterUtil.java:77)
	at org.eclipse.birt.report.engine.layout.html.HTMLTableLayoutEmitter.startContent(HTMLTableLayoutEmitter.java:146)
	at org.eclipse.birt.report.engine.emitter.ContentEmitterAdapter.startForeign(ContentEmitterAdapter.java:168)
	at org.eclipse.birt.report.engine.emitter.ContentEmitterUtil.startContent(ContentEmitterUtil.java:77)
	at org.eclipse.birt.report.engine.layout.html.HTMLTableLayoutEmitter.startContent(HTMLTableLayoutEmitter.java:146)
	at org.eclipse.birt.report.engine.emitter.ContentEmitterAdapter.startForeign(ContentEmitterAdapter.java:168)
	at org.eclipse.birt.report.engine.emitter.ContentEmitterUtil.startContent(ContentEmitterUtil.java:77)
	at org.eclipse.birt.report.engine.layout.html.buffer.HTMLPageBuffer.startContent(HTMLPageBuffer.java:116)
	at org.eclipse.birt.report.engine.layout.html.buffer.TableBreakBuffer.startContent(TableBreakBuffer.java:286)
	at org.eclipse.birt.report.engine.layout.html.HTMLLeafItemLM.start(HTMLLeafItemLM.java:67)
	at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:139)
	at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:70)
	at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:26)
	at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:140)
	at org.eclipse.birt.report.engine.layout.html.HTMLInlineStackingLM.resumeLayout(HTMLInlineStackingLM.java:111)
	at org.eclipse.birt.report.engine.layout.html.HTMLInlineStackingLM.layoutNodes(HTMLInlineStackingLM.java:160)
	at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:26)
	at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:140)
	at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:70)
	at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:26)
	at org.eclipse.birt.report.engine.layout.html.HTMLTableBandLM.layoutChildren(HTMLTableBandLM.java:67)
	at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:140)
	at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:70)
	at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:26)
	at org.eclipse.birt.report.engine.layout.html.HTMLTableLM.layoutChildren(HTMLTableLM.java:132)
	at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:140)
	at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:70)
	at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:26)
	at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:140)
	at org.eclipse.birt.report.engine.layout.html.HTMLInlineStackingLM.resumeLayout(HTMLInlineStackingLM.java:111)
	at org.eclipse.birt.report.engine.layout.html.HTMLInlineStackingLM.layoutNodes(HTMLInlineStackingLM.java:160)
	at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:26)
	at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:140)
	at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:70)
	at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:26)
	at org.eclipse.birt.report.engine.layout.html.HTMLTableBandLM.layoutChildren(HTMLTableBandLM.java:67)
	at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:140)
	at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:48)
	at org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:26)
	at org.eclipse.birt.report.engine.layout.html.HTMLTableLM.layoutChildren(HTMLTableLM.java:132)
	at org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:140)
	at org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:48)
	at org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout(HTMLPageLM.java:90)
	at org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutEngine.layout(HTMLReportLayoutEngine.java:99)
	at org.eclipse.birt.report.engine.presentation.ReportDocumentBuilder.build(ReportDocumentBuilder.java:249)
	at org.eclipse.birt.report.engine.api.impl.RunTask.doRun(RunTask.java:252)
	at org.eclipse.birt.report.engine.api.impl.RunTask.run(RunTask.java:85)
	at com.ibm.rmc.publishing.doc.service.DocumentGenerator$1.run(DocumentGenerator.java:105)
	at java.lang.Thread.run(Thread.java:736)
//////////////////

Reproducible: Always
Comment 1 Alex Chen CLA 2010-09-06 23:04:55 EDT
Our html contents in report like this:

 <tbody>
   <tr>
     <td width="5%">
     <b>Purpose:</b>&#160;
     </td>
     <td width="95%">
        Ensure attendee's are invited and are adequately informed about the review.
     </td>
  </tr><!-- Input_Output Artifacts Begins --><!-- Input_Output Artifact End --><!-- Activity Tool Mentors -->
 </tbody>
Comment 2 Alex Chen CLA 2010-09-06 23:05:39 EDT
Created attachment 178290 [details]
The log file during generating pdf/word report