[MAGNOLIA-3082] DefaultClassFactory.newInstance(Class<T>, Class<?>[], Object...) should not use invokeExactConstructor but invokeConstructor Created: 16/Feb/10  Updated: 23/Jan/13  Resolved: 22/Mar/10

Status: Closed
Project: Magnolia
Component/s: None
Affects Version/s: 4.3
Fix Version/s: 4.3

Type: Improvement Priority: Major
Reporter: Philipp Bärfuss Assignee: Magnolia International
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
relation
is related to MAGNOLIA-3012 Replace usages of FactoryUtil/ClassUtil Closed
is related to MAGNOLIA-3081 use generics in the rendering model (... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Date of First Response:

 Description   

The method DefaultClassFactory.newInstance(Class<T>, Object...) calls ConstructorUtils.invokeConstructor(Class, Object[]) while this is not the case for DefaultClassFactory.newInstance(Class<T>, Class<?>[], Object...).

This is especially a problem if you have more precise constructors in subclasses (especially if you use generics).

Example: after introducing generics for models (MAGNOLIA-3081) the method AbstractRenderable.newModel(...) fails to find the correct constructor.



 Comments   
Comment by Magnolia International [ 17/Feb/10 ]

Now that I read the tests again, I'm not sure about this anymore. I see why we need it - but it's the second part of testCanInstantiateWithBestMatchingConstructorWhenTheSignatureIsMorePrecise() I don't feel comfortable with. IMO, we should be able to do

classFactory.newInstance(FooBar.class, arr(Baz.class), someInstanceOfABazSubclass)

- ie we know the constructor takes exactly 1 Baz instance, and we pass it whatever we have. If you can't do that, you either

  • create an array with the types of your arguments with defaults to handle nulls
  • use the newInstance(class, args) variation of the method, and can't have null parameters.

In any case, we should also have a couple of tests using generics to validate the cases in question.

Comment by Magnolia International [ 22/Mar/10 ]

Good enough for now; we might need more improvements the day we introduce real IOC, but that might be covered by the container.

Generated at Mon Feb 12 03:43:00 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.