Project: JDT
Bug 218339 [breadcrumb] ClassCastException if JavaEditor is nested within a GridLayout
Reported: 2008-02-08 11:49:16 | Status: resolved fixed

Build ID: I20080122-0800 Steps To Reproduce: I am using the v20080122-8000 version of org.eclipse.jdt.ui. I have a JavaEditor instance embedded within in a GridLayout in a custom view. Due to the recent additions to the JavaEditor to handle breadcrumbs I am experiencing a ClassCastException which has rendered my view unusable. The exception is happening for the following reasons... 1. In the createSourceViewer method of org.eclipse.jdt.internal.ui.javaeditor.JavaEditor you set the top level composite to have a layout data of type GridData. Composite composite= new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); In my case, and I believe when you just open the Java Editor normally, the parent composite has a FillLayout, so applying a GridData has no real impact and can lead to a ClassCastException. 2. The ClassCastException comes about when FillLayout attempts to compute its size. In the method computeChildSize in org.eclipse.swt.layout.FillLayout there is the following line of code: FillData data = (FillData)control.getLayoutData (); At this point the control(the JavaEditor composite), which has its layout data set as a GridData object, will cause a ClassCastException. This exception does not pop up during the standard case of just opening the JavaEditor because there is no top level GridLayout which has to compute the size of its children. In my case I have the JavaEditor embedded in a top level GridLayout so it has to compute the size of its children in order to lay itself out. This takes it down the code path which leads to the ClassCastException. More information: I was able fix this problem by doing a quick check in the JavaEditor class. In the createSourceViewer method of org.eclipse.jdt.internal.ui.javaeditor.JavaEditor I modified the code... From: Composite composite= new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); To: Composite composite= new Composite(parent, SWT.NONE); if(parent.getLayout() != null && parent.getLayout() instanceof GridLayout) { composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); } An if statement to check that the parent layout is in fact a GridLayout before a GridData is applied to it. Another option would be to just not set the layout data if the parent is always going to be a FillLayout. Please let me know if you require any additional information.

Files changed in fix:
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java