[MAGNOLIA-5317] i18nizer: Default values set in a constructor override a previously configured value Created: 16/Sep/13 Updated: 03/Oct/13 Resolved: 30/Sep/13 |
|
| Status: | Closed |
| Project: | Magnolia |
| Component/s: | i18n |
| Affects Version/s: | 5.1.1 |
| Fix Version/s: | 5.1 |
| Type: | Bug | Priority: | Major |
| Reporter: | Eric Hechinger | Assignee: | Magnolia International |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | i18n | ||
| 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)
|
||||||||||||||||||||||||||||||||||||
| Bug DoR: |
[ ]*
Steps to reproduce, expected, and actual results filled
[ ]*
Affected version filled
|
||||||||||||||||||||||||||||||||||||
| Date of First Response: | |||||||||||||||||||||||||||||||||||||
| Sprint: | 5.1 - Final | ||||||||||||||||||||||||||||||||||||
| Description |
|
When a proxied bean sets a default for some field in its constructor, via a setter method (which is often done especially in subclasses that provide some default/specific behavior), the "manually" configured value gets overriden. The call flow goes like this: class Obj = { Obj() { setFoo("default") } void setFoo(String) {} } obj = new Obj()// sets foo to "default" obj.setFoo("my configured value") d = i18nizer.decorate(obj) // proxy creation involves invoking the constructor of d assertEquals("my configured value", d.getFoo() // fails, d.getFoo() returns "default" This is a problem inherent to class-based proxies - the constructor of the generated subclass (the proxy) is called when instanciating it. This inherently invokes the original class' constructor, which calls setFoo() in this example. Since in our case, all methods (thus including setFoo) are decorating and delegate to the original underlying object, this overwrites the configured value. One possible pattern against this would be to have a protected constructor which takes the default values as arguments; subclasses which want to set default values for certain properties could have a single public no-arg constructor, which delegates to this super construct with the default values instead of calling the corresponding setters. This has the disadvantage that anything that potentially needs a default value should be exposed in the super constructor; which isn't always practical, since one doesn't always have access to the source code thereof. Another possibility to investigate is to see if we could somehow "delay" the delegation/decoration until after the subclass/proxy is instanciated. I'm however not sure how that would play with other things such as init() methods and so on. Currently impacted by this : FieldDefinition with transformerClass - see |
| Comments |
| Comment by Magnolia International [ 20/Sep/13 ] |
|
The solution with the least impact, most transparency is to "defer" delegation; only enable it once the proxy is instantiated. While we could work around this on our end (perhaps with yet another proxy, such as a HotSwap), a simple patch in proxytoys seems to fix the issue, but using cglib's interceptDuringConstruction option. I proposed a patch to the ProxyToys team, and if all goes well that could lead to a release as early as this weekend. |
| Comment by Magnolia International [ 30/Sep/13 ] |
|
We won't get the updated release of Proxytoys in time for 5.1 release, so here goes. |