ActiveObjects Implementation class requires constructor args

I have the following test case:

public class Foo extends Entity {

    public Integer getRepoId();
    public void setRepoId(Integer id);

    public Repository getRepository();

public class FooImpl {

    private final Foo foo;
    private final RepositoryService rs;

    public FooImpl(Foo foo, RepositoryService rs) { = foo; = rs;
    public Repository getRepository() {
        return repositoryService.getById(foo.getRepoId());

When I try to use this code, I get NPEs because, it seems, AO silently fails to construct the FooImpl object (see the code in and in the activeobjects code here:

How can I write implementation code which depends upon a component spring must wire up, such as RepositoryService? ALso, is this a bug in AO that it doesn't provide a better error? The error I got looked like this:

	at org.hsqldb.jdbc.jdbcResultSet.findColumn(Unknown Source)
	at org.hsqldb.jdbc.jdbcResultSet.getObject(Unknown Source)
	at $Proxy22.getLCName(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(
	at org.junit.internal.runners.statements.RunBefores.evaluate(
	at org.junit.runners.ParentRunner.runLeaf(
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(
	at org.junit.runners.ParentRunner$
	at org.junit.runners.ParentRunner$1.schedule(
	at org.junit.runners.ParentRunner.runChildren(
	at org.junit.runners.ParentRunner.access$000(
	at org.junit.runners.ParentRunner$2.evaluate(
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(

(in this instance, TestCase is Foo and TestCaseImpl is FooImpl, and getLCName is the method implemented by the impl class)

2 answers

Just to add, I am pretty sure of the cause because after a lengthy debugging session, I removed the extra arguments from the constructor and the error went away (but of course, my code doesn't work because I need repositoryService). Also, as I said, I read the AO code.

Hi Carl,

I'm afraid, unless I'm mistaken, that you can't use inject Spring beans into your AO beans. These are meant to be simple data transfer objects (DTOs).

Instead you normally want to load (or create) an instance of Foo in a service/component X, which has injected (via the constructor) an instance of RepositoryService. You can then lookup the Stash repository from the id of the Foo repoId. Don't try to mix the two.

If you get stuck I might suggest putting some code on Bitbucket/Github so that we can look at and perhaps provide some pointers.



PS. Apologies if you've seen these before:

Also the official Atlassian version of AO is kept here:

Charles - thanks for your reply. I see how to make a workaround, it's just less clean. That said, I'm still of the mind that the inability to construct an Impl class using the dependency injection framework of your choice (such as spring) is an AO bug, and I'm *sure* the way this particular error surfaces is an error. Shouldn't construction fail? Maybe an IllegalArgumentException could be thrown from the init() method of ?

Hi Carl,

I'm not sure I entirely agree that you should be able to inject your impl classes with services - does Hibernate allow you to do that for example?

In any case, I agree the construction should fail with an IAE. If you want to raise a bug you might want to start here:



Thanks Charles!

I don't seem to have permission to open/change issues on that jira instance (I created a new account since it seems to be disconnected from answers auth).

I found a duplicate issue resolved as "won't fix" but I think at a minimum we should reopen the issue or open a linked issue to fix the error handling. The similar issue I found is here:

I would like to also open a feature request which is as follows:

Modify the code that interacts with @Implementation so if FooImpl.class implements FactoryBean interface (or something like that) then instead of treating it as the Impl class, it uses that factory bean to construct the new object. This should allow people to have custom constructors with minimal changes to the code.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


251 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you