[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: |
|
||||||||||||
| 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 ( |
| 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
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. |