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

Bug 360288

Summary: service variable can't initialized if using a function in the library
Product: z_Archived Reporter: Jing Qian <jqian>
Component: EDTAssignee: Project Inbox <edt.javascriptgen-inbox>
Status: CLOSED FIXED QA Contact:
Severity: blocker    
Priority: P3 CC: jvincens, pharmon, svihovec
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Jing Qian CLA 2011-10-07 17:20:17 EDT
This is blocking issue, because I'm porting existing services tests from RBD, 
I need to initialize the service variable based on the enumeration type

I have the following library and ruiHandler,
I'm trying to initialize service variable via the initService() function
This gives me exception when running the RUIhandler in preview (did not try in deploy mode)


import services.myservice;

library myLib
		
	variableName string = initString();
	s myservice = initService();
	
	function initString() returns (String)
		return ("jing jing");
	end
	
	function initService() returns (myservice)
		s1 myservice{@DedicatedService};
		return (s1);
	end
	
end


handler h1 type RUIhandler{initialUI =[
            ], onConstructionFunction = start, cssFile = "css/a.css", title = "h1"}
    function start()
    	syslib.writeStdout(myLib.variableName);
    end
end
Comment 1 Joseph Vincens CLA 2011-10-10 20:42:36 EDT
This is a compiler problem should not be able to declare an interface or service without a ?. Here is the corrected library:
library myLib

    variableName string = initString();
    s myservice? = initService();

    function initString() returns (String)
        return ("jing jing");
    end

    function initService() returns (myservice)
        s1 myservice?{@DedicatedService};
        return (s1);
    end

end
When there is no ? the generator tries to instantiate a new instance of the service. You can't instantiate a myservice so an exception is throw.
Comment 2 Paul Harmon CLA 2011-10-11 11:14:02 EDT
Routing back to JS Gen. JS generator should generate "null" as the new instance of a service, instead of attempting to instantiate the non-existant service.
Comment 3 Brian Svihovec CLA 2011-10-11 11:44:11 EDT
I talked with Paul about this, and he claimed that this issue was sent back to JS Generation because creating a variable of type Service with out a '?' will be allowed in Java.  Is this true?  I was under the impression that a Service must always be bound to a 'resource', even if that service is specified in a batch Java application and is referencing a Dedicated Service?

Also, it seems that this issue is no longer a blocker and can probably be moved to a severity of 'normal'.  If that is the case, please make this change.
Comment 4 Jing Qian CLA 2011-10-11 12:07:18 EDT
lower to normal, p1, as I changed the code according to Joe's suggestion, it
works correctly.
Comment 5 Joseph Vincens CLA 2011-10-13 12:50:03 EDT
fixed.
Instead of making this a validation error the js generator set the instantiation to null.
Comment 6 Joseph Vincens CLA 2011-10-13 14:27:17 EDT
Brian had a meeting about this defect. 
In RBD we don't allow the instantiation of a service part. A local service is called by binding it and then using the binding to invoke the service. 
In RBD local service behave differently than a REST or SOAP because at the end of a REST or SOAP function the run unit is ended, with a local call the rununit is the same run unit as the caller.
We have not defined how local services should behave in EDT. Instead of allowing user to instantiate a service part in 070 and then trying to remove that functionality in 10 it would be better to restrict it now by not allow the creation of a new service instance. 
So validation should not allow a service type without a ?.
Comment 7 Paul Harmon CLA 2011-10-14 12:28:52 EDT
I have updated ServiceBinding to make services be not instantiable. This results in all variables that are typed to a service to either:
1) be nullable   and/or
2) have an initializer
Comment 8 Lisa Lasher CLA 2011-11-09 14:13:30 EST
This high severity defect was fixed several weeks ago, so I am closing.