Statement should find the public named 'newInstance()' method of target class rather than throwing a NoSuchMethodException

git-svn-id: https://svn.apache.org/repos/asf/harmony/enhanced/classlib/trunk@905197 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/modules/beans/src/main/java/java/beans/Statement.java b/modules/beans/src/main/java/java/beans/Statement.java
index bf3c36d..4eed390 100644
--- a/modules/beans/src/main/java/java/beans/Statement.java
+++ b/modules/beans/src/main/java/java/beans/Statement.java
@@ -135,7 +135,13 @@
                     Constructor<?> constructor = findConstructor((Class)theTarget, theArguments);
                     result = constructor.newInstance(theArguments);
                 } else {
-                    throw new NoSuchMethodException(this.toString());
+                    if ("new".equals(theMethodName)) { //$NON-NLS-1$
+                        throw new NoSuchMethodException(this.toString());
+                    }
+                    // target class declares a public named "newInstance" method
+                    Method method = findMethod(theTarget.getClass(),
+                            theMethodName, theArguments, false);
+                    result = method.invoke(theTarget, theArguments);
                 }
             } else if (theMethodName.equals("newArray")) {//$NON-NLS-1$
                 // create a new array instance without length attribute
diff --git a/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java b/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java
index 994c63f..cd16067 100644
--- a/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java
+++ b/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java
@@ -853,6 +853,32 @@
         assertFalse(MockTarget.isCalled());
     }
 
+    public void testGetValue_newInstanceNormalMethod() throws Exception {
+        Expression expression = new Expression(new NormalTarget(),
+                "newInstance", new Object[0]);
+        assertEquals("Normal-Called", expression.getValue());
+    }
+
+    public void testGetValue_newInstanceStaticMethod() throws Exception {
+        Expression expression = new Expression(new StaticTarget(),
+                "newInstance", new Object[0]);
+        assertEquals("Static-Called", expression.getValue());
+    }
+
+    public class NormalTarget {
+
+        public String newInstance() {
+            return "Normal-Called";
+        }
+    }
+
+    public static class StaticTarget {
+
+        public static String newInstance() {
+            return "Static-Called";
+        }
+    }
+
     /*
      * Test the method getValue() with two equal specific methods.
      *