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

Bug 357825

Summary: TypeCastException using ::= with an array of records
Product: z_Archived Reporter: Kathy Carroll <carrollk>
Component: EDTAssignee: Jeff Douglas <jeffdouglas>
Status: CLOSED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: mheitz
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Kathy Carroll CLA 2011-09-15 11:15:10 EDT
:= doesn't work but appendElement does.  this is critical because the test frameowrk uses it

when I run my java generated code I get a TypeCastException

program driver type BasicProgram {}
	
	function main()
		root2 ResultSummaryRoot;
		persistResult2(root2);
		
		root ResultSummaryRoot;
		persistResult(root);
	end
	
	function persistResult( resultRootSum ResultSummaryRoot)
		resultSum ResultSummary;
		resultSum.name = "one";		
		resultRootSum.trSum ::= resultSum;
				
		resultSum2 ResultSummary;
		resultSum2.name = "two";		
		resultRootSum.trSum ::= resultSum2;
	end
	
	function persistResult2( resultRootSum ResultSummaryRoot)
		resultSum ResultSummary;
		resultSum.name = "one2";		
		resultRootSum.trSum.appendElement(resultSum);
				
		resultSum2 ResultSummary;
		resultSum2.name = "two2";		
		resultRootSum.trSum.appendElement(resultSum2);
	end
end

Record ResultSummary
	pkgName String {@XMLAttribute{}}; 
	name String{@XMLAttribute{}};	 
end

Record ResultSummaryRoot {@xmlrootelement {}}
	expCnt int{@XMLAttribute{}};		 
	trSum ResultSummary[]{};
end
Comment 1 Matt Heitz CLA 2011-09-15 12:19:19 EDT
We're generating the ::= as appendAll, but it should be appendElement.
Comment 2 Matt Heitz CLA 2011-09-15 12:40:37 EDT
The problem was in IRUtils.makeCompatible(Assignment).  It didn't understand that ::= is sometimes array.appendElement(), so it was creating IRs that told the generator to turn the record into an array.  When that conversion failed at run time, the TypeCastException was thrown.
Comment 3 Kathy Carroll CLA 2011-09-16 11:28:03 EDT
using install build 201109152102 I get 

Multiple markers at this line
	- IWN.JavaGen.9998.e 18/369 Exception occurred: 
	 java.lang.NullPointerException
	- IWN.JavaGen.9999.e 18/369 Stack Trace: java.lang.NullPointerException

on EGL line

   resultRootSum.trSum ::= resultSum;
Comment 4 Jeff Douglas CLA 2011-09-16 19:45:05 EDT
That statement has been fixed, although if you code it as:

array = array :: record

then you will get the same problem. It's because there is no classifier for a record and that causes the NPE in makeCompat.

Will look into it
Comment 5 Matt Heitz CLA 2011-09-19 08:22:29 EDT
Changing the target milestone since we're in I-15 now.
Comment 6 Jeff Douglas CLA 2011-09-19 15:50:59 EDT
fixed
Comment 7 Kathy Carroll CLA 2011-09-20 08:21:50 EDT
works in 201109192102
Comment 8 Lisa Lasher CLA 2011-10-11 16:28:55 EDT
Closing this defect.