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

Bug 350710

Summary: get class cast exception on for statement for the isIncrement method call
Product: z_Archived Reporter: Jeff Douglas <jeffdouglas>
Component: EDTAssignee: Paul Harmon <pharmon>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jspadea, jvincens
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Patch for the CCE and MofObjectNotFoundException lasher: iplog+

Description Jeff Douglas CLA 2011-06-29 10:39:00 EDT
package acme.xxxx;

program Bug
f1_int int;
	function main()
		for (f1_int from 1 to 100)
		end
	end
end

intermittently, I get a class cast exception on for statement for the isIncrement method call

Caused by: org.eclipse.edt.mof.serialization.MofObjectNotFoundException: MofObject not found: egl:egl.lang.eglboolean
	at org.eclipse.edt.mof.serialization.AbstractEnvironment.find(AbstractEnvironment.java:120)
	at org.eclipse.edt.mof.serialization.AbstractEnvironment.find(AbstractEnvironment.java:96)
	at org.eclipse.edt.mof.egl.utils.IRUtils.getType(IRUtils.java:259)
Comment 1 Justin Spadea CLA 2011-07-01 15:27:12 EDT
Hi Paul, I debugged this one and it looks like a problem when deserializing ForStatement from the compiler's mofar. In XMLDeserializer.valueFromString() it falls into the last "else" branch. The EDataType for the "initialValue" attribute on the "isIncrement" field is org.eclipse.edt.mof.JavaObject instead of EBoolean, so it doesn't convert "true" to a Boolean object (stores the value as a String).

Also, I was not getting the error Jeff pasted below. He mentions a ClassCastException, which is what I get, but he pasted a MofObjectNotFoundException.

To reproduce the CCE, run a clean on the project, and make sure you have the Java generator enabled for the project (build deserializes the IR with the wrong type for isIncrement, and generation invokes ForStatement.isIncrement() which causes the CCE).
Comment 2 Justin Spadea CLA 2011-07-07 09:32:37 EDT
I did some more digging on Jeff's stack trace, and I think the problem is with IsNotExpressionImpl.getType(). It's looking for "egl.lang.EGLBoolean", and I found no other references or declarations of this type anywhere in the code/mofars/eglars. If you look at IsAExpressionImpl.getType(), it returns TypeUtils.Type_BOOLEAN, which is probably what IsNotExpressionImpl.getType() should be returning.

To reproduce:

record myrec
    s string;
end

program prog1
    function main()
        m myrec;
        if (m.s is blanks)
        end
    end
end
Comment 3 Joseph Vincens CLA 2011-07-13 15:20:58 EDT
I'm also seeing a classcastexception (java.lang.String cannot be cast to java.lang.Boolean) on the XMLAttribute and XMLElement annotation fields that are type boolean (nillable/required) using the record below. 

The classcast only happens when I clean the project, if I edit the file to force a build the annotation default value is a Boolean like it should be. I tested Jeff's scenario and it also behaves this way. 

record Record1{@XMLRootElement{name="root_name", namespace="root_namepsace", nillable=true}}
	f1 string;
	f2 string{@XMLElement};
	f3 string{@XMLAttribute};
	f4 string{@XMLElement{name="f4_name", namespace="f4_namepsace", nillable=true}};
	f5 string{@XMLAttribute{name="f5_name", namespace="f5_namepsace", required=true}};
end
Comment 4 Justin Spadea CLA 2011-07-15 13:22:37 EDT
Created attachment 199762 [details]
Patch for the CCE and MofObjectNotFoundException

Paul - I've attached a patch that resolves both Jeff and Joe's issues. Please review it and let me know if it looks correct. As for the code I put into EFieldImpl.getInitialValue(), I don't know if any other types should be checked. I went by what was in EDataTypeImpl.getDefaultValue(), except I omitted the case for java.util.List. I added an array field to one of the types, gave it an initial value, recompiled the .mofxml file and the initial value was not included in the IR. I do not know if this is a bug or if we don't support initial values for array fields.
Comment 5 Justin Spadea CLA 2011-07-18 13:03:45 EDT
Patch has been applied and released
Comment 6 Lisa Lasher CLA 2011-11-02 10:36:04 EDT
closing this defect, which was fixed several months ago