@@ -104,38 +104,37 @@ public static UriComponentsBuilder fromController(Class<?> controllerType) {
104
104
private static String getTypeRequestMapping (Class <?> controllerType ) {
105
105
Assert .notNull (controllerType , "'controllerType' must not be null" );
106
106
RequestMapping annot = AnnotationUtils .findAnnotation (controllerType , RequestMapping .class );
107
- if (( annot == null ) || ObjectUtils .isEmpty (annot .value ()) || StringUtils .isEmpty (annot .value ()[0 ])) {
107
+ if (annot == null || ObjectUtils .isEmpty (annot .value ()) || StringUtils .isEmpty (annot .value ()[0 ])) {
108
108
return "/" ;
109
109
}
110
- if (annot .value ().length > 1 ) {
111
- if (logger .isWarnEnabled ()) {
112
- logger .warn ("Multiple paths on controller " + controllerType .getName () + ", using first one" );
113
- }
110
+ if (annot .value ().length > 1 && logger .isWarnEnabled ()) {
111
+ logger .warn ("Multiple paths on controller " + controllerType .getName () + ", using first one" );
114
112
}
115
113
return annot .value ()[0 ];
116
114
}
117
115
118
116
/**
119
- * Create a {@link UriComponentsBuilder} from the mapping of a controller method
120
- * and an array of method argument values. This method delegates to
121
- * {@link #fromMethod(java.lang.reflect.Method, Object...)}.
117
+ * Create a {@link UriComponentsBuilder} from the mapping of a controller
118
+ * method and an array of method argument values. This method delegates
119
+ * to {@link #fromMethod(java.lang.reflect.Method, Object...)}.
122
120
* @param controllerType the controller
123
121
* @param methodName the method name
124
122
* @param argumentValues the argument values
125
123
* @return a UriComponentsBuilder instance, never {@code null}
126
- * @throws IllegalStateException if there is no matching or more than one matching method
124
+ * @throws IllegalArgumentException if there is no matching or
125
+ * if there is more than one matching method
127
126
*/
128
127
public static UriComponentsBuilder fromMethodName (Class <?> controllerType , String methodName , Object ... argumentValues ) {
129
128
Method method = getMethod (controllerType , methodName , argumentValues );
130
129
return fromMethod (method , argumentValues );
131
130
}
132
131
133
- private static Method getMethod (Class <?> controllerType , String methodName , Object [] argumentValues ) {
132
+ private static Method getMethod (Class <?> controllerType , String methodName , Object ... argumentValues ) {
134
133
Method match = null ;
135
134
for (Method method : controllerType .getDeclaredMethods ()) {
136
135
if (method .getName ().equals (methodName ) && method .getParameterTypes ().length == argumentValues .length ) {
137
136
if (match != null ) {
138
- throw new IllegalStateException ("Found two methods named '" + methodName + "' having " +
137
+ throw new IllegalArgumentException ("Found two methods named '" + methodName + "' having " +
139
138
Arrays .asList (argumentValues ) + " arguments, controller " + controllerType .getName ());
140
139
}
141
140
match = method ;
@@ -212,19 +211,19 @@ public static UriComponentsBuilder fromMethod(Method method, Object... argumentV
212
211
213
212
private static String getMethodRequestMapping (Method method ) {
214
213
RequestMapping annot = AnnotationUtils .findAnnotation (method , RequestMapping .class );
215
- Assert .notNull (annot , "No @RequestMapping on: " + method .toGenericString ());
214
+ if (annot == null ) {
215
+ throw new IllegalArgumentException ("No @RequestMapping on: " + method .toGenericString ());
216
+ }
216
217
if (ObjectUtils .isEmpty (annot .value ()) || StringUtils .isEmpty (annot .value ()[0 ])) {
217
218
return "/" ;
218
219
}
219
- if (annot .value ().length > 1 ) {
220
- if (logger .isWarnEnabled ()) {
221
- logger .warn ("Multiple paths on method " + method .toGenericString () + ", using first one" );
222
- }
220
+ if (annot .value ().length > 1 && logger .isWarnEnabled ()) {
221
+ logger .warn ("Multiple paths on method " + method .toGenericString () + ", using first one" );
223
222
}
224
223
return annot .value ()[0 ];
225
224
}
226
225
227
- private static UriComponents applyContributors (UriComponentsBuilder builder , Method method , Object [] args ) {
226
+ private static UriComponents applyContributors (UriComponentsBuilder builder , Method method , Object ... args ) {
228
227
CompositeUriComponentsContributor contributor = getConfiguredUriComponentsContributor ();
229
228
if (contributor == null ) {
230
229
logger .debug ("Using default CompositeUriComponentsContributor" );
@@ -233,8 +232,10 @@ private static UriComponents applyContributors(UriComponentsBuilder builder, Met
233
232
234
233
int paramCount = method .getParameterTypes ().length ;
235
234
int argCount = args .length ;
236
- Assert .isTrue (paramCount == argCount , "Number of method parameters " + paramCount +
237
- " does not match number of argument values " + argCount );
235
+ if (paramCount != argCount ) {
236
+ throw new IllegalArgumentException ("Number of method parameters " + paramCount +
237
+ " does not match number of argument values " + argCount );
238
+ }
238
239
239
240
final Map <String , Object > uriVars = new HashMap <String , Object >();
240
241
for (int i = 0 ; i < paramCount ; i ++) {
0 commit comments