Harmony
  1. Harmony
  2. HARMONY-4392

[classlib][beans]java.beans.Statement/Expression cannot handle overloaded constructor properly

    Details

    • Estimated Complexity:
      Moderate

      Description

      Consider test case below[1], which is extracted from o.a.h.beans.tests.java.beans.ExpressionTest. Seems RI 5 and 6 return different results, further, both results depend on the constructors' order in MockObject and follow a mysterious rules, while in spec, it is required to "choose the most specific method using the algorithm specified in the Java Language Specification". More interesting stuffs is, if you construct a Statement, Expression's superclass, in same way, RI 5 has different result, although in spec, the only difference between the 2 classes are Expression adds a value property.

      My guess on RI's behavior is it tries to list all constructors via reflection and then check them one by one whether all parameter is assignable, at last returns the first matching result, so the result actually depends on VM's reflection implementation. Current Harmony's beans actually works in similar way, but unfortunately the different VMs just return constructors in different ways, including different version of RI.

      So the issue now is if we need to fix it as spec or let it be in "random" behavior as RI? I prefer to fix Harmony to follow spec.

      [1]
      public ExpressionTest extends TestCase{
      public void testGetValue_UnboundedOverloadedConstructors() throws Exception {
      arguments = new Object[]

      { "test" }

      ;
      t = new Expression(MockObject.class, "new", arguments);
      assertTrue(t.getValue() instanceof MockObject);
      MockObject.assertCalled("new3", arguments);

      arguments = new Object[]

      { new Integer(1) }

      ;
      t = new Expression(MockObject.class, "new", arguments);
      assertTrue(t.getValue() instanceof MockObject);
      MockObject.assertCalled("new1-2", arguments);
      }

      public static class MockObject{
      public MockObject(String o)

      { reset(); calledMethod = "new3"; receivedArguments.add(o); }

      public MockObject(Object o)

      { reset(); calledMethod = "new2"; receivedArguments.add(o); }

      public MockObject(Integer o)

      { reset(); calledMethod = "new1-2"; receivedArguments.add(o); }

      public static void assertCalled(String methodName, Object[] arguments)

      { assertEquals(methodName, calledMethod); assertTrue(Arrays.equals(arguments, receivedArguments.toArray())); reset(); }

      public static void reset()

      { receivedArguments.clear(); calledMethod = null; }

      }
      }

        Activity

        Kevin Zhou made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Estimated Complexity Unknown Moderate
        Oliver Deakin made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 6.0M2 [ 12314804 ]
        Fix Version/s 5.0M14 [ 12314803 ]
        Resolution Fixed [ 1 ]
        Oliver Deakin made changes -
        Assignee Oliver Deakin [ odeakin ]
        Kevin Zhou made changes -
        Field Original Value New Value
        Attachment HARMONY-4392.diff [ 12441275 ]
        Paulex Yang created issue -

          People

          • Assignee:
            Oliver Deakin
            Reporter:
            Paulex Yang
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development