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

Bug 362145

Summary: Generated Java code got error when the external type can not be instantiated
Product: z_Archived Reporter: Xin Wu <cdlwuxin>
Component: EDTAssignee: Project Inbox <edt.javagen-inbox>
Status: CLOSED INVALID QA Contact:
Severity: major    
Priority: P3 CC: jqian, jvincens, margolis
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
LdapRuiServices in EDT
none
The updated project, you may use this instead the old one none

Description Xin Wu CLA 2011-10-26 23:11:32 EDT
Build Identifier: 20111026 nightly build

Generated Java code got error when the external type can not be instantiated

Reproducible: Always

Steps to Reproduce:
1. Download the attached EDT EGL project, import to your workspace
2. Make sure there is no EGL compile error and see the "Attribute" External type in EGL file "common.LDAPExternalTypes.egl". This was modified based on project in RBD.
3. See the file "common.UserObject.java" in generatedJava, there are some Java compile error for "Attribute" pointing out it can not be instantiated.
4. The doesn't occurred in RBD, you may get comparable project in RBD by 
Help => Samples => EGL => Rich UI access to LDAP
Comment 1 Xin Wu CLA 2011-10-26 23:14:22 EDT
Created attachment 206043 [details]
LdapRuiServices in EDT
Comment 2 Xin Wu CLA 2011-10-31 03:03:38 EDT
A similar problem in same project.

In generatedJava -> common -> LDAPLib.java line 34.
"InitialLdapContext ctx = new InitialLdapContext();" got error unhandled exception. Which was declared as "null" in RBD.

These two problem blocked some of the Green Thread testing, so I will reset severity to major.
Comment 3 Xin Wu CLA 2011-10-31 03:53:45 EDT
Created attachment 206191 [details]
The updated project, you may use this instead the old one
Comment 4 Joseph Vincens CLA 2011-11-01 13:49:55 EDT
The Attributes external type represents an interface. An interface is not instantiatable, so the egl variable declaration should have a ?. A best practice when creating an external type that represents a Java Interface is to have a private constructor.
externalType Attributes type JavaObject
	{ ExternalName = "Attributes", PackageName = "javax.naming.directory" }	
	private constructor();
	function getAttribute( attrId String in ) returns( Attribute ) { ExternalName = "get" };
	function getAll() returns ( NamingEnumeration );
	function getIds() returns ( NamingEnumeration );
	function size() returns ( int );
end

This forces the variable declaration to require a ?.
		attrs 		Attributes?;
Comment 5 Joseph Vincens CLA 2011-11-01 13:51:28 EDT
If you want InitialLdapContext to be initialized to null, then you need to define it as nullable. ie
ctx InitialLdapContext?;
Comment 6 Xin Wu CLA 2011-11-01 23:16:03 EDT
Joe, thanks so much.

The best practice you suggested that adding "private constructor();" solved the problem. And it will bring out a  compile error to notify user to add a '?' in EGL. 

Closed this bug.