Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Services are not injected in generated controllers if the length of the class name is one #44

Open
amador-duran-toro opened this issue May 10, 2020 · 2 comments
Labels

Comments

@amador-duran-toro
Copy link

In Grails 4.0.3 and Grails 3.3.11, if you have a domain class named A, e.g.

package mypackage

abstract class A {
  String name
  // ...
  // properties
  // ...
}

And you populate it in Bootstrap.groovy, e.g.

package mypackage

class BootStrap {

    def init = { servletContext ->
        A.withTransaction { status ->
            A.saveAll( 
                new A( name: "a1" ),
                new A( name: "a2" ),
                new A( name: "a3" )
            )
        }
    }
    def destroy = {
    }
}

If you use scaffolding (create-scaffold-controller A), everything works correctly.

But if you delete the scaffolding controller and generate-all for your class A, everything fails throwing a java.lang.NullPointerException because the AService aService object is null in AController.groovy, i.e. the service object is not properly injected in the controller.

Now, if you delete all the generated files except the domain class file (A.groovy), rename the file and the class as, let's say, A1, and generate-all again, everything works!

You can try with any one-letter named classes, e.g. A, B, X, etc., and the generated code always fails for the same reason. Add another character to the class name, regenerate, and everything works!

I suppose there must be some name clash somewhere when a class is named with a single character.

@osscontributor
Copy link
Member

The generated scaffolding code should include AService AService, not AService aService.

@osscontributor
Copy link
Member

@amador-duran-toro FYI... The BootStrap code that you quoted in the question doesn't have any affect on and is not affected by the scaffolding issue in question. I don't think BootStrap should be involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants