commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Barney Barumba (JIRA)" <j...@apache.org>
Subject [jira] [Created] (DIGESTER-180) Digester calls invalid method when using proxy ObjectCreate rule
Date Tue, 23 Dec 2014 16:53:13 GMT
Barney Barumba created DIGESTER-180:
---------------------------------------

             Summary: 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


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)

Mime
View raw message