bobobear / lambdaj

Automatically exported from code.google.com/p/lambdaj
Apache License 2.0
0 stars 0 forks source link

Method calls in constructor are invoked on entire collection #65

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
  static class NonInterfaceItem {

    private int value;

    public NonInterfaceItem() {
      setValue(10); // Set default value 
    }

    public int getValue() {
      return value;
    }

    public void setValue(int value) {
      this.value = value;
    }
  }

  @Test
  public void callsFromConstructorAreForwarded() {
    NonInterfaceItem item1 = new NonInterfaceItem();
    item1.setValue(20);

    NonInterfaceItem item2 = new NonInterfaceItem();
    item2.setValue(50);

    assertEquals(70, sumFrom(asList(item1, item2)).getValue()); // Fail - is 20
    assertEquals(20, item1.getValue()); // Fail - is 10
    assertEquals(50, item2.getValue()); // Fail - is 10
  }

What version of the product are you using?
2.3.2

Please provide any additional information below.
I think it should be possible to solve this by deactivating the 
ProxyIterator/ProxyAggregator (either ignoring all calls or forwarding them to 
the actual CGLib proxy instance) until the CGLib enhancer creation is done in 
ProxyUtil.createProxy()

Original issue reported on code.google.com by mattias....@gmail.com on 3 May 2011 at 1:53

GoogleCodeExporter commented 9 years ago
Until this is changed, it should probably be mentioned on 
http://code.google.com/p/lambdaj/wiki/KnownLimitations

Original comment by mattias....@gmail.com on 3 May 2011 at 1:56

GoogleCodeExporter commented 9 years ago
Attached is a patch that solves this by ignoring all method calls while proxy 
construction is in progress. (I'm not sure whether there may be cases when 
those method calls need to be invoked on the cglib proxy instance, but that 
seems to require are lot more effort)

Original comment by mattias....@gmail.com on 4 May 2011 at 2:54

Attachments:

GoogleCodeExporter commented 9 years ago
fixed in release 2.3.3

Original comment by mario.fu...@gmail.com on 20 May 2011 at 8:49