You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by zh...@apache.org on 2010/02/01 08:16:45 UTC
svn commit: r905197 - in /harmony/enhanced/classlib/trunk/modules/beans/src:
main/java/java/beans/Statement.java
test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java
Author: zhoukevin
Date: Mon Feb 1 07:16:45 2010
New Revision: 905197
URL: http://svn.apache.org/viewvc?rev=905197&view=rev
Log:
Statement should find the public named 'newInstance()' method of target class rather than throwing a NoSuchMethodException
Modified:
harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java
harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java
Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java?rev=905197&r1=905196&r2=905197&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java (original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java Mon Feb 1 07:16:45 2010
@@ -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
Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java?rev=905197&r1=905196&r2=905197&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java Mon Feb 1 07:16:45 2010
@@ -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.
*