You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2012/10/21 23:13:06 UTC

svn commit: r1400727 - /maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/reflection/Reflector.java

Author: rfscholte
Date: Sun Oct 21 21:13:06 2012
New Revision: 1400727

URL: http://svn.apache.org/viewvc?rev=1400727&view=rev
Log:
Remove redundant null-check: getMethod()/getConstructor() never returns null. If it's not there, it'll throw a ReflectorException

Modified:
    maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/reflection/Reflector.java

Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/reflection/Reflector.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/reflection/Reflector.java?rev=1400727&r1=1400726&r2=1400727&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/reflection/Reflector.java (original)
+++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/reflection/Reflector.java Sun Oct 21 21:13:06 2012
@@ -77,25 +77,6 @@ final class Reflector
         {
             Constructor con = getConstructor( theClass, paramTypes );
 
-            if ( con == null )
-            {
-                StringBuilder buffer = new StringBuilder();
-
-                buffer.append( "Constructor not found for class: " );
-                buffer.append( theClass.getName() );
-                buffer.append( " with specified or ancestor parameter classes: " );
-
-                for ( Class paramType : paramTypes )
-                {
-                    buffer.append( paramType.getName() );
-                    buffer.append( ',' );
-                }
-
-                buffer.setLength( buffer.length() - 1 );
-
-                throw new ReflectorException( buffer.toString() );
-            }
-
             return con.newInstance( params );
         }
         catch ( InstantiationException ex )
@@ -175,23 +156,6 @@ final class Reflector
         {
             Method method = getMethod( target.getClass(), methodName, paramTypes );
 
-            if ( method == null )
-            {
-                StringBuilder buffer = new StringBuilder();
-
-                buffer.append( "Singleton-producing method named '" ).append( methodName ).append( "' not found with specified parameter classes: " );
-
-                for ( Class paramType : paramTypes )
-                {
-                    buffer.append( paramType.getName() );
-                    buffer.append( ',' );
-                }
-
-                buffer.setLength( buffer.length() - 1 );
-
-                throw new ReflectorException( buffer.toString() );
-            }
-
             return method.invoke( target, params );
         }
         catch ( InvocationTargetException ex )
@@ -312,23 +276,6 @@ final class Reflector
         {
             Method method = getMethod( targetClass, methodName, paramTypes );
 
-            if ( method == null )
-            {
-                StringBuilder buffer = new StringBuilder();
-
-                buffer.append( "Singleton-producing method named \'" ).append( methodName ).append( "\' not found with specified parameter classes: " );
-
-                for ( Class paramType : paramTypes )
-                {
-                    buffer.append( paramType.getName() );
-                    buffer.append( ',' );
-                }
-
-                buffer.setLength( buffer.length() - 1 );
-
-                throw new ReflectorException( buffer.toString() );
-            }
-
             return method.invoke( null, params );
         }
         catch ( InvocationTargetException ex )
@@ -346,7 +293,7 @@ final class Reflector
      * 
      * @param targetClass The class to get the constructor from
      * @param params The classes of the parameters which the constructor should match.
-     * @return the Constructor object that matches.
+     * @return the Constructor object that matches, never {@code null}
      * @throws ReflectorException In case we can't retrieve the proper constructor.
      */
     public Constructor<?> getConstructor( Class targetClass, Class... params )
@@ -478,7 +425,7 @@ final class Reflector
      * 
      * @param targetClass The class to get the method from
      * @param params The classes of the parameters which the method should match.
-     * @return the Method object that matches.
+     * @return the Method object that matches, never {@code null}
      * @throws ReflectorException In case we can't retrieve the proper method.
      */
     public Method getMethod( Class<?> targetClass, String methodName, Class<?>... params )