[ 
https://issues.apache.org/jira/browse/DIGESTER-180?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Barney Barumba updated DIGESTER-180:
------------------------------------
    Attachment: Box.java

Full source code of test.

> Digester calls invalid method when using proxy ObjectCreate rule
> ----------------------------------------------------------------
>
>                 Key: DIGESTER-180
>                 URL: https://issues.apache.org/jira/browse/DIGESTER-180
>             Project: Commons Digester
>          Issue Type: Bug
>    Affects Versions: 3.2
>         Environment: Linux x_86_64, JDK 1.7.0_65
>            Reporter: Barney Barumba
>         Attachments: Box.java
>
>
> Hi, I've encountered some strange behaviour when using the new proxy object 
> create: the digester appears to call a method that is never mentioned in the 
> digester rules! I've simplified it as much as I can to the following (full, 
> runnable code attached):
> A simple box of widgets:
> {code}
>   private final String id;
>   private final Set<String> widgetIds = new HashSet<>();
>   
>   public Box(String id) {
>     System.out.println("Box: id=" + id);
>     this.id = id;
>   }
>   
>   public void addWidget(String widgetId) {
>     System.out.println("addWidget: id=" + id + ", wid=" + widgetId);
>     addWidgetInternal(widgetId);
>   }
>   
>   public void addWidgetInternal(String widgetId) {
>     System.out.println("addWidgetInternal: id=" + id + ", wid=" + widgetId);
>     if (widgetIds.contains(widgetId)) {
>       System.err.println("*** box already contains widget " + widgetId);
>     } else {
>       widgetIds.add(widgetId);
>     }
>   }
> {code}
> The source XML is fairly straightforward:
> {code}
> <box id='b01'>
>   <widget wid='w01'>Widget 1</widget>
> </box>
> {code}
> as are the rules:
> {code}
>   forPattern("box")
>       .createObject().ofType(Box.class).usingConstructor(String.class)
>       .usingDefaultConstructorArguments("")
>       .then().callParam().fromAttribute("id").ofIndex(0);
>     
>   forPattern("box/widget")
>       .callMethod("addWidget")
>       .withParamCount(1)
>       .then().callParam().fromAttribute("wid").ofIndex(0);
> {code}
> The key point here is that the rules only ever invoke {{addWidget}}, and this 
> calls {{addWidgetInternal}}. However, when I run this, {{addWidgetInternal}} 
> gets called twice, the second time directly from the digester, and I get the 
> following output:
> {code}
> Box: id=
> addWidget: id=, wid=w01
> addWidgetInternal: id=, wid=w01
> Box: id=b01
> addWidget: id=b01, wid=w01
> addWidgetInternal: id=b01, wid=w01
> addWidgetInternal: id=b01, wid=w01
> *** box already contains widget w01
> {code}
> I'm guessing that this is connected with the proxy code because I can change 
> any number of things to make it work:
> * Make {{addWidgetInternal}} private;
> * Call {{addWidgetInternal}} directly from the digester rules.
> * Use a custom object create rule instead (see attached code).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to