Griffon
  1. Griffon
  2. GRIFFON-535

Better information when a service constructor fails

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0.0
    • Fix Version/s: 1.0.2
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Currently if a service artifact throws an exception during construction, then the application fails with an unhelpful "unable to call setApp() on a null instance" exception from the GriffonApplicationHelper#enhance method.

      The problem is that GriffonApplicationHelper#safeNewInstance eats the exception thrown from the constructor then returns null, which seems wrong.

        Activity

        Show
        Andres Almiray added a comment - Fixed with https://github.com/griffon/griffon/commit/187ed7d97a933d225d43d4e7a988dadbaf42f614
        Hide
        Andres Almiray added a comment -

        For a service class defined as

        package foo
        
        class FooService {
            FooService() {
                throw new IllegalArgumentException('FOO!')
            }
        
            def serviceMethod() {
        
            }
        }
        

        you'll get the following error message when attempting to instantiate it through the conventional Griffon way

        2012-07-16 21:00:34,259 [main] INFO  griffon.swing.SwingApplication - Initializing all startup groups: [foo]
        2012-07-16 21:00:35,769 [main] ERROR griffon.util.GriffonExceptionHandler - Uncaught Exception
        griffon.exceptions.NewInstanceCreationException: Could not create a new instance of class foo.FooController
        	at org.codehaus.griffon.runtime.core.AbstractGriffonClass.newInstance(AbstractGriffonClass.java:121)
        	at org.codehaus.griffon.runtime.core.DefaultMVCGroupManager.instantiateMembers(DefaultMVCGroupManager.java:207)
        	at org.codehaus.griffon.runtime.core.DefaultMVCGroupManager.buildMVCGroup(DefaultMVCGroupManager.java:112)
        	at org.codehaus.griffon.runtime.core.AbstractMVCGroupManager.createMVCGroup(AbstractMVCGroupManager.java:238)
        	at org.codehaus.griffon.runtime.core.AbstractMVCGroupManager.createMVCGroup(AbstractMVCGroupManager.java:186)
        	at org.codehaus.griffon.runtime.core.AbstractGriffonApplication.createMVCGroup(AbstractGriffonApplication.java:474)
        	at org.codehaus.griffon.runtime.core.AbstractGriffonApplication.startup(AbstractGriffonApplication.java:313)
        	at griffon.swing.AbstractSwingGriffonApplication.realize(AbstractSwingGriffonApplication.java:78)
        	at griffon.swing.AbstractSwingGriffonApplication.run(AbstractSwingGriffonApplication.java:132)
        	at griffon.swing.SwingApplication.main(SwingApplication.java:36)
        Caused by: griffon.exceptions.NewInstanceCreationException: Could not create a new instance of class foo.FooService
        	at org.codehaus.griffon.runtime.core.AbstractGriffonClass.newInstance(AbstractGriffonClass.java:121)
        	at org.codehaus.griffon.runtime.core.ServiceArtifactHandler$DefaultServiceManager.instantiateService(ServiceArtifactHandler.java:69)
        	at org.codehaus.griffon.runtime.core.ServiceArtifactHandler$DefaultServiceManager.findService(ServiceArtifactHandler.java:61)
        	at org.codehaus.griffon.runtime.core.ServiceArtifactHandler.onNewInstance(ServiceArtifactHandler.java:115)
        	at org.codehaus.griffon.runtime.core.EventRouter.fireEvent(EventRouter.java:271)
        	at org.codehaus.griffon.runtime.core.EventRouter.access$700(EventRouter.java:53)
        	at org.codehaus.griffon.runtime.core.EventRouter$2.run(EventRouter.java:218)
        	at org.codehaus.griffon.runtime.core.EventRouter.publish(EventRouter.java:132)
        	at org.codehaus.griffon.runtime.core.AbstractGriffonApplication.event(AbstractGriffonApplication.java:336)
        	at org.codehaus.griffon.runtime.util.GriffonApplicationHelper.newInstance(GriffonApplicationHelper.java:411)
        	at org.codehaus.griffon.runtime.core.AbstractGriffonClass.newInstance(AbstractGriffonClass.java:111)
        	... 9 more
        Caused by: java.lang.IllegalArgumentException: FOO!
        	at foo.FooService.<init>(FooService.groovy:5)
        	at org.codehaus.griffon.runtime.util.GriffonApplicationHelper.newInstance(GriffonApplicationHelper.java:399)
        	at org.codehaus.griffon.runtime.core.AbstractGriffonClass.newInstance(AbstractGriffonClass.java:111)
        	... 19 more
        
        Show
        Andres Almiray added a comment - For a service class defined as package foo class FooService { FooService() { throw new IllegalArgumentException('FOO!') } def serviceMethod() { } } you'll get the following error message when attempting to instantiate it through the conventional Griffon way 2012-07-16 21:00:34,259 [main] INFO griffon.swing.SwingApplication - Initializing all startup groups: [foo] 2012-07-16 21:00:35,769 [main] ERROR griffon.util.GriffonExceptionHandler - Uncaught Exception griffon.exceptions.NewInstanceCreationException: Could not create a new instance of class foo.FooController at org.codehaus.griffon.runtime.core.AbstractGriffonClass.newInstance(AbstractGriffonClass.java:121) at org.codehaus.griffon.runtime.core.DefaultMVCGroupManager.instantiateMembers(DefaultMVCGroupManager.java:207) at org.codehaus.griffon.runtime.core.DefaultMVCGroupManager.buildMVCGroup(DefaultMVCGroupManager.java:112) at org.codehaus.griffon.runtime.core.AbstractMVCGroupManager.createMVCGroup(AbstractMVCGroupManager.java:238) at org.codehaus.griffon.runtime.core.AbstractMVCGroupManager.createMVCGroup(AbstractMVCGroupManager.java:186) at org.codehaus.griffon.runtime.core.AbstractGriffonApplication.createMVCGroup(AbstractGriffonApplication.java:474) at org.codehaus.griffon.runtime.core.AbstractGriffonApplication.startup(AbstractGriffonApplication.java:313) at griffon.swing.AbstractSwingGriffonApplication.realize(AbstractSwingGriffonApplication.java:78) at griffon.swing.AbstractSwingGriffonApplication.run(AbstractSwingGriffonApplication.java:132) at griffon.swing.SwingApplication.main(SwingApplication.java:36) Caused by: griffon.exceptions.NewInstanceCreationException: Could not create a new instance of class foo.FooService at org.codehaus.griffon.runtime.core.AbstractGriffonClass.newInstance(AbstractGriffonClass.java:121) at org.codehaus.griffon.runtime.core.ServiceArtifactHandler$DefaultServiceManager.instantiateService(ServiceArtifactHandler.java:69) at org.codehaus.griffon.runtime.core.ServiceArtifactHandler$DefaultServiceManager.findService(ServiceArtifactHandler.java:61) at org.codehaus.griffon.runtime.core.ServiceArtifactHandler.onNewInstance(ServiceArtifactHandler.java:115) at org.codehaus.griffon.runtime.core.EventRouter.fireEvent(EventRouter.java:271) at org.codehaus.griffon.runtime.core.EventRouter.access$700(EventRouter.java:53) at org.codehaus.griffon.runtime.core.EventRouter$2.run(EventRouter.java:218) at org.codehaus.griffon.runtime.core.EventRouter.publish(EventRouter.java:132) at org.codehaus.griffon.runtime.core.AbstractGriffonApplication.event(AbstractGriffonApplication.java:336) at org.codehaus.griffon.runtime.util.GriffonApplicationHelper.newInstance(GriffonApplicationHelper.java:411) at org.codehaus.griffon.runtime.core.AbstractGriffonClass.newInstance(AbstractGriffonClass.java:111) ... 9 more Caused by: java.lang.IllegalArgumentException: FOO! at foo.FooService.<init>(FooService.groovy:5) at org.codehaus.griffon.runtime.util.GriffonApplicationHelper.newInstance(GriffonApplicationHelper.java:399) at org.codehaus.griffon.runtime.core.AbstractGriffonClass.newInstance(AbstractGriffonClass.java:111) ... 19 more

          People

          • Assignee:
            Andres Almiray
            Reporter:
            Steve Ash
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: