Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » Autogenerated object not available in a lifecycle hook ?
Autogenerated object not available in a lifecycle hook ? [message #1624251] Thu, 19 February 2015 17:15 Go to next message
Thomas Elskens is currently offline Thomas ElskensFriend
Messages: 159
Registered: September 2014
Location: Brussels - Belgium
Senior Member
Hello,

I was trying out the @Creatable annotation for a loginmanager class, but it doesn't seem to work.

Before, I had a code like this :

//...
@PostContextCreate
public LifecycleRV manageLogin(UISynchronize sync, @FXMLLoader FXMLLoaderFactory factory, IDomainManager domainManager)
{
	LoginManager manager = new LoginManager(logger) ;
	return manager.showLogin(sync, factory, domainManager) ;
}


This worked, but I had to inject a lot of dependencies where they were not actually needed and pass them around, so I tried instead :

@Creatable
@Singleton
public class LoginManager
{
//...
@Inject
public LoginManager(Logger logger, UISynchronize sync, FXMLLoaderFactory factory, IDomainManager domainManager)
{
	this.logger = logger ;
	FxmlFactory = factory ;
	this.sync = sync ;
	this.domainManager = domainManager ;	
}


And so, in the lifecycle hook, I now have :

@PostContextCreate
public LifecycleRV manageLogin(LoginManager loginManager)
{
	return loginManager.showLogin() ;
}


But this does not work at all: the PostContextCreate simply doesn't get called any longer.

So my question is : can I use this kind of injection in a lifecycle hook ? Or am I doing something wrong ?

Regards,

Thomas Elskens
Re: Autogenerated object not available in a lifecycle hook ? [message #1624280 is a reply to message #1624251] Thu, 19 February 2015 17:36 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
You are missing the @FXMLLoader in the constructor
Re: Autogenerated object not available in a lifecycle hook ? [message #1625236 is a reply to message #1624280] Fri, 20 February 2015 08:35 Go to previous messageGo to next message
Thomas Elskens is currently offline Thomas ElskensFriend
Messages: 159
Registered: September 2014
Location: Brussels - Belgium
Senior Member
Oups, that are the dangers of copy-paste... But unfortunately, it still doesn't work. I now get the following exception :

Quote:

!ENTRY org.eclipse.equinox.app 4 0 2015-02-20 09:26:48.913
!MESSAGE Exception in Application start method
!STACK 0
java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(LauncherImpl.java:182)
at com.sun.javafx.application.LauncherImpl$$Lambda$9/2107886461.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
at org.eclipse.fx.ui.workbench.fx.internal.UISynchronizeImpl.syncExec(UISynchronizeImpl.java:54)
at org.eclipse.fx.ui.workbench.base.AbstractE4Application.invokePostContextCreate(AbstractE4Application.java:308)
at org.eclipse.fx.ui.workbench.base.AbstractE4Application.createE4Workbench(AbstractE4Application.java:229)
at org.eclipse.fx.ui.workbench.fx.E4Application.initE4Workbench(E4Application.java:259)
at org.eclipse.fx.ui.workbench.fx.E4Application$1.run(E4Application.java:134)
at org.eclipse.fx.ui.workbench.fx.E4Application.jfxStart(E4Application.java:169)
at org.eclipse.fx.ui.workbench.fx.DefaultJFXApp.start(DefaultJFXApp.java:57)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863)
at com.sun.javafx.application.LauncherImpl$$Lambda$58/961163379.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl$$Lambda$54/2044326795.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$56/938427494.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
at com.sun.javafx.application.PlatformImpl$$Lambda$55/1059156002.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$45/1071610017.run(Unknown Source)
... 1 more
Caused by: java.lang.NullPointerException
at org.eclipse.fx.ui.di.internal.FXMLLoaderSupplier.get(FXMLLoaderSupplier.java:42)
at org.eclipse.e4.core.internal.di.InjectorImpl.resolveArgs(InjectorImpl.java:456)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:330)
at org.eclipse.e4.core.internal.di.InjectorImpl.resolveArgs(InjectorImpl.java:492)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:239)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:225)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:107)
at org.eclipse.fx.ui.workbench.base.AbstractE4Application$2.call(AbstractE4Application.java:311)
at org.eclipse.fx.ui.workbench.fx.internal.UISynchronizeImpl.syncExec(UISynchronizeImpl.java:52)
... 20 more


When I remove the FXMLLoaderFactory from the constructor and pass it around, like this :
@PostContextCreate
public LifecycleRV manageLogin(LoginManager loginManager, @FXMLLoader FXMLLoaderFactory factory)
{
	return loginManager.showLogin(factory) ;
}

then once again, this method doesn't get called any longer ?
Re: Autogenerated object not available in a lifecycle hook ? [message #1633060 is a reply to message #1625236] Tue, 24 February 2015 16:59 Go to previous messageGo to next message
Thomas Elskens is currently offline Thomas ElskensFriend
Messages: 159
Registered: September 2014
Location: Brussels - Belgium
Senior Member
I did some testing and came up with this.

When trying to inject the Creatable object as a field or in the PostConstruct annotated method the error I get is quite different :
Quote:

!ENTRY org.eclipse.equinox.app 4 0 2015-02-24 17:02:13.921
!MESSAGE Exception in Application start method
!STACK 0
java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(LauncherImpl.java:182)
at com.sun.javafx.application.LauncherImpl$$Lambda$9/1542677606.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at org.eclipse.fx.ui.di.internal.FXMLLoaderSupplier.get(FXMLLoaderSupplier.java:42)
at org.eclipse.e4.core.internal.di.InjectorImpl.resolveArgs(InjectorImpl.java:456)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:330)
at org.eclipse.e4.core.internal.di.InjectorImpl.resolveArgs(InjectorImpl.java:492)
at org.eclipse.e4.core.internal.di.InjectorImpl.resolveRequestorArgs(InjectorImpl.java:397)
at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:109)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:337)
at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:258)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:104)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:73)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:55)
at org.eclipse.fx.ui.workbench.base.AbstractE4Application.createE4Workbench(AbstractE4Application.java:227)
at org.eclipse.fx.ui.workbench.fx.E4Application.initE4Workbench(E4Application.java:259)
at org.eclipse.fx.ui.workbench.fx.E4Application$1.run(E4Application.java:134)
at org.eclipse.fx.ui.workbench.fx.E4Application.jfxStart(E4Application.java:169)
at org.eclipse.fx.ui.workbench.fx.DefaultJFXApp.start(DefaultJFXApp.java:57)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863)
at com.sun.javafx.application.LauncherImpl$$Lambda$58/1832951554.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl$$Lambda$54/1902432953.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$56/2111769866.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
at com.sun.javafx.application.PlatformImpl$$Lambda$55/1135883852.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$45/1189893830.run(Unknown Source)
... 1 more


As these error stacks seem to suggest the problem resides in the arguments UISynchronize and FXMLLoaderFactory, I removed them from constructor of the Creatable object and inject them in the PostContexCreate instead, still another error:

Quote:

!ENTRY org.eclipse.e4.ui.workbench 4 0 2015-02-24 17:46:41.153
!MESSAGE Unable to create class 'be.groups.portfolio.extension.lifecyclemanager.LifecycleManager' from bundle '564'
!STACK 0
org.eclipse.e4.core.di.InjectionException: Unable to process "LifecycleManager.loginManager": no actual value was found for the argument "LoginManager".
at org.eclipse.e4.core.internal.di.InjectorImpl.reportUnresolvedArgument(InjectorImpl.java:416)
at org.eclipse.e4.core.internal.di.InjectorImpl.resolveRequestorArgs(InjectorImpl.java:407)
at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:109)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:337)
at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:258)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:104)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:73)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:55)
at org.eclipse.fx.ui.workbench.base.AbstractE4Application.createE4Workbench(AbstractE4Application.java:227)
at org.eclipse.fx.ui.workbench.fx.E4Application.initE4Workbench(E4Application.java:259)
at org.eclipse.fx.ui.workbench.fx.E4Application$1.run(E4Application.java:134)
at org.eclipse.fx.ui.workbench.fx.E4Application.jfxStart(E4Application.java:169)
at org.eclipse.fx.ui.workbench.fx.DefaultJFXApp.start(DefaultJFXApp.java:57)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863)
at com.sun.javafx.application.LauncherImpl$$Lambda$58/923728878.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl$$Lambda$53/83194686.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$56/1875485712.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
at com.sun.javafx.application.PlatformImpl$$Lambda$54/808138063.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$45/433317014.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)


I've read here (https://www.eclipse.org/forums/index.php/t/397553/) that is possible to use a Creatable Object in a PostContextCreate, so that cannot be the problem.

I'm running out of ideas... And I really would like to understand why this doesn't work : I'm only injecting a logger, a home-made OSGi service, a UISynchronize and a FXMLLoaderFactory, all of which function normally when injected directly in the PostContextCreate method...

Any hints would be really welcome,

Thomas
Re: Autogenerated object not available in a lifecycle hook ? [message #1636617 is a reply to message #1633060] Thu, 26 February 2015 09:30 Go to previous messageGo to next message
Thomas Elskens is currently offline Thomas ElskensFriend
Messages: 159
Registered: September 2014
Location: Brussels - Belgium
Senior Member
I don't understand why, but following workaround solved the issue. Instead of using the Creatable annotation with constructor injection, I used ContextInjectionFactory (with field injection for all dependencies) :

	@PostContextCreate
	public LifecycleRV manageLogin(IEclipseContext localContext)
	{
		LoginManager manager = ContextInjectionFactory.make(LoginManager.class, localContext) ;
		return manager.showLogin() ;
	}


Thomas
Re: Autogenerated object not available in a lifecycle hook ? [message #1636856 is a reply to message #1625236] Thu, 26 February 2015 12:06 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Ok this looks like a bug in FXMLLoaderSupplier which should use

final Class<?> requestingClass = requestor.getRequestingObjectClass();

Please file a bug!

Tom

On 20.02.15 09:35, Thomas Elskens wrote:
> Oups, that are the dangers of copy-paste... But unfortunately, it still
> doesn't work. I now get the following exception :
>
> Quote:
>> !ENTRY org.eclipse.equinox.app 4 0 2015-02-20 09:26:48.913
>> !MESSAGE Exception in Application start method
>> !STACK 0
>> java.lang.RuntimeException: Exception in Application start method
>> at
>> com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
>>
>> at
>> com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(LauncherImpl.java:182)
>>
>> at
>> com.sun.javafx.application.LauncherImpl$$Lambda$9/2107886461.run(Unknown
>> Source)
>> at java.lang.Thread.run(Thread.java:745)
>> Caused by: java.lang.RuntimeException: java.lang.NullPointerException
>> at
>> org.eclipse.fx.ui.workbench.fx.internal.UISynchronizeImpl.syncExec(UISynchronizeImpl.java:54)
>>
>> at
>> org.eclipse.fx.ui.workbench.base.AbstractE4Application.invokePostContextCreate(AbstractE4Application.java:308)
>>
>> at
>> org.eclipse.fx.ui.workbench.base.AbstractE4Application.createE4Workbench(AbstractE4Application.java:229)
>>
>> at
>> org.eclipse.fx.ui.workbench.fx.E4Application.initE4Workbench(E4Application.java:259)
>>
>> at
>> org.eclipse.fx.ui.workbench.fx.E4Application$1.run(E4Application.java:134)
>>
>> at
>> org.eclipse.fx.ui.workbench.fx.E4Application.jfxStart(E4Application.java:169)
>>
>> at
>> org.eclipse.fx.ui.workbench.fx.DefaultJFXApp.start(DefaultJFXApp.java:57)
>> at
>> com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863)
>>
>> at
>> com.sun.javafx.application.LauncherImpl$$Lambda$58/961163379.run(Unknown
>> Source)
>> at
>> com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326)
>>
>> at
>> com.sun.javafx.application.PlatformImpl$$Lambda$54/2044326795.run(Unknown
>> Source)
>> at
>> com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
>>
>> at
>> com.sun.javafx.application.PlatformImpl$$Lambda$56/938427494.run(Unknown
>> Source)
>> at java.security.AccessController.doPrivileged(Native Method)
>> at
>> com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
>>
>> at
>> com.sun.javafx.application.PlatformImpl$$Lambda$55/1059156002.run(Unknown
>> Source)
>> at
>> com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
>>
>> at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
>> at
>> com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
>>
>> at
>> com.sun.glass.ui.win.WinApplication$$Lambda$45/1071610017.run(Unknown
>> Source)
>> ... 1 more
>> Caused by: java.lang.NullPointerException
>> at
>> org.eclipse.fx.ui.di.internal.FXMLLoaderSupplier.get(FXMLLoaderSupplier.java:42)
>>
>> at
>> org.eclipse.e4.core.internal.di.InjectorImpl.resolveArgs(InjectorImpl.java:456)
>>
>> at
>> org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:330)
>>
>> at
>> org.eclipse.e4.core.internal.di.InjectorImpl.resolveArgs(InjectorImpl.java:492)
>>
>> at
>> org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:239)
>>
>> at
>> org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:225)
>>
>> at
>> org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:107)
>>
>> at
>> org.eclipse.fx.ui.workbench.base.AbstractE4Application$2.call(AbstractE4Application.java:311)
>>
>> at
>> org.eclipse.fx.ui.workbench.fx.internal.UISynchronizeImpl.syncExec(UISynchronizeImpl.java:52)
>>
>> ... 20 more
>
>
> When I remove the FXMLLoaderFactory from the constructor and pass it
> around, like this :
>
> @PostContextCreate
> public LifecycleRV manageLogin(LoginManager loginManager, @FXMLLoader
> FXMLLoaderFactory factory)
> {
> return loginManager.showLogin(factory) ;
> }
>
> then once again, this method doesn't get called any longer ?
Re: Autogenerated object not available in a lifecycle hook ? [message #1636959 is a reply to message #1636856] Thu, 26 February 2015 13:12 Go to previous message
Thomas Elskens is currently offline Thomas ElskensFriend
Messages: 159
Registered: September 2014
Location: Brussels - Belgium
Senior Member
Bug created as https://bugs.eclipse.org/bugs/show_bug.cgi?id=460939

Thomas
Previous Topic:Core expressions not evaluated at runtime
Next Topic:Scenic View
Goto Forum:
  


Current Time: Fri Jan 17 19:32:58 GMT 2025

Powered by FUDForum. Page generated in 0.03663 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top