Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 350214 - ClassCastException happened when event handle class added to an image item.
Summary: ClassCastException happened when event handle class added to an image item.
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: BIRT (show other bugs)
Version: 2.6.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7.1   Edit
Assignee: Birt-ReportEngine-inbox@eclipse.org CLA
QA Contact: Xiaoying Gu CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-24 03:13 EDT by yadong xu CLA
Modified: 2011-06-29 23:29 EDT (History)
3 users (show)

See Also:


Attachments
patch.txt (13.10 KB, text/plain)
2011-06-28 23:04 EDT, Jianchao Li CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description yadong xu CLA 2011-06-24 03:13:44 EDT
Build Identifier: 2.6.1

in this method:
org.eclipse.birt.report.engine.script.internal.OnPageBreakScriptVisitor.OnPageBreakExecutor.visitImageItem(ImageItemDesign, Object)
the second variable should be an IImageContent type object, but it is actually an ITextContent at runtime.

Reproducible: Always

Steps to Reproduce:
1.create an image item in a grid.
2.add an event handle class to the image.
3.preview.
Comment 1 yadong xu CLA 2011-06-24 03:17:24 EDT
Caused by: java.lang.ClassCastException: org.eclipse.birt.report.engine.content.impl.TextContent cannot be cast to org.eclipse.birt.report.engine.content.IImageContent
   at org.eclipse.birt.report.engine.script.internal.OnPageBreakScriptVisitor$OnPageBreakExecutor.visitImageItem(OnPageBreakScriptVisitor.java:210)
   at org.eclipse.birt.report.engine.ir.ImageItemDesign.accept(ImageItemDesign.java:89)
   at org.eclipse.birt.report.engine.script.internal.OnPageBreakScriptVisitor.onPageBreak(OnPageBreakScriptVisitor.java:132)
   at org.eclipse.birt.report.engine.executor.OnPageBreakLayoutPageHandle.onPage(OnPageBreakLayoutPageHandle.java:207)
   at org.eclipse.birt.report.engine.layout.CompositeLayoutPageHandler.onPage(CompositeLayoutPageHandler.java:33)
   at org.eclipse.birt.report.engine.nLayout.LayoutEngine.outputPage(LayoutEngine.java:829)
   at org.eclipse.birt.report.engine.nLayout.area.impl.PageArea.outputPage(PageArea.java:704)
   at org.eclipse.birt.report.engine.nLayout.area.impl.PageArea.close(PageArea.java:684)
   at org.eclipse.birt.report.engine.nLayout.area.impl.RootArea.close(RootArea.java:215)
   at org.eclipse.birt.report.engine.nLayout.LayoutEngine.closeContainer(LayoutEngine.java:360)
   at org.eclipse.birt.report.engine.nLayout.LayoutEngine._endContainer(LayoutEngine.java:437)
   at org.eclipse.birt.report.engine.nLayout.LayoutEngine.endContainer(LayoutEngine.java:346)
   at org.eclipse.birt.report.engine.emitter.ContentEmitterAdapter.endPage(ContentEmitterAdapter.java:70)
   at org.eclipse.birt.report.engine.emitter.ContentEmitterUtil.endContent(ContentEmitterUtil.java:102)
   at org.eclipse.birt.report.engine.layout.html.buffer.PageNode.end(PageNode.java:33)
   at org.eclipse.birt.report.engine.layout.html.buffer.HTMLPageBuffer.endPage(HTMLPageBuffer.java:292)
   at org.eclipse.birt.report.engine.layout.html.buffer.HTMLPageBuffer.endContainer(HTMLPageBuffer.java:136)
   at org.eclipse.birt.report.engine.layout.html.buffer.TableBreakBuffer.endContainer(TableBreakBuffer.java:421)
   at org.eclipse.birt.report.engine.layout.html.HTMLPageLM.end(HTMLPageLM.java:181)
   at org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout(HTMLPageLM.java:96)
   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:260)
... 50 more
Comment 2 Jun Ouyang CLA 2011-06-24 03:19:40 EDT
Please attach the report design.

If remove the event handler, is the image displayed or is it displayed as alt text?
Comment 3 yadong xu CLA 2011-06-24 03:51:39 EDT
when i remove the image's event handle class, it display ok.
I have no report design file for standard birt.
I modified birt to write,compile and load event handle class for easy, but the invoke part is same as the original.
(In reply to comment #2)
> Please attach the report design.
> 
> If remove the event handler, is the image displayed or is it displayed as alt
> text?
Comment 4 yadong xu CLA 2011-06-24 03:56:58 EDT
(In reply to comment #3)
> when i remove the image's event handle class, it display ok.
> I have no report design file for standard birt.
> I modified birt to write,compile and load event handle class for easy, but the
> invoke part is same as the original.
> (In reply to comment #2)
> > Please attach the report design.
> > 
> > If remove the event handler, is the image displayed or is it displayed as alt
> > text?

in the class: org.eclipse.birt.report.engine.script.internal.OnPageBreakScriptVisitor
after i comment the pagebreak event of the image, the image display ok.

public Object visitImageItem( ImageItemDesign image, Object value )
{	
//ImageScriptExecutor.handleOnPageBreak( (IImageContent) value,context );
return value;
}
Comment 5 Jianchao Li CLA 2011-06-28 04:34:52 EDT
create an UnsupportedImageInstance for TextContent, which always do nothing excepting returning the text as the altText for the image item.
Comment 6 yadong xu CLA 2011-06-28 22:37:05 EDT
(In reply to comment #5)
> create an UnsupportedImageInstance for TextContent, which always do nothing
> excepting returning the text as the altText for the image item.

I don't konw how to do this, and i can't find the class: UnsupportedImageInstance.
I hope you can fix this bug in next version and i comment image's pagebreak event now.
Comment 7 Jun Ouyang CLA 2011-06-28 22:38:28 EDT
Jianchao, can you give yadong a patch?
Comment 8 yadong xu CLA 2011-06-28 22:54:32 EDT
(In reply to comment #7)
> Jianchao, can you give yadong a patch?

SourceCode is ok ,i can build and jar myself.
Comment 9 Jianchao Li CLA 2011-06-28 23:04:54 EDT
Created attachment 198782 [details]
patch.txt

Please apply the attached patch against BIRT 2.6.1
Comment 10 yadong xu CLA 2011-06-28 23:27:11 EDT
(In reply to comment #9)
> Created attachment 198782 [details]
> patch.txt
> 
> Please apply the attached patch against BIRT 2.6.1

Thank you very much!
Does it mean when i use image' pagebreak event, i should convert the first argument ImageInstance to UnsupportedImageInstance at first?

public void onPageBreak(IImageInstance image, IReportContext reportcontext) throws ScriptException {
    UnsupportedImageInstance ui =  (UnsupportedImageInstance) image;
    .....	
}
Comment 11 Jun Ouyang CLA 2011-06-28 23:31:43 EDT
It depends if you have to distinguish if it's an image supported or not.

For an unsupported image, only get/setAltText is valid. Other "getters" return null, "setters" do nothing.
Comment 12 yadong xu CLA 2011-06-28 23:35:35 EDT
(In reply to comment #11)
> It depends if you have to distinguish if it's an image supported or not.
> 
> For an unsupported image, only get/setAltText is valid. Other "getters" return
> null, "setters" do nothing.

I know.
We want to our programmer can change the image by get/set URI, and thanks again.