From 6825287360e7d881066b7fbd16ab7e970985c225 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 9 Nov 2020 18:18:33 +0100 Subject: [PATCH] Polishing --- .../web/method/annotation/MapMethodProcessor.java | 10 +++++----- .../method/annotation/ModelMethodProcessor.java | 6 +++--- .../PrincipalMethodArgumentResolver.java | 15 +++++---------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java b/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java index fa5cfc4677..4f1480b567 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,8 +42,8 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle @Override public boolean supportsParameter(MethodParameter parameter) { - return Map.class.isAssignableFrom(parameter.getParameterType()) && - parameter.getParameterAnnotations().length == 0; + return (Map.class.isAssignableFrom(parameter.getParameterType()) && + parameter.getParameterAnnotations().length == 0); } @Override @@ -70,8 +70,8 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle } else if (returnValue != null) { // should not happen - throw new UnsupportedOperationException("Unexpected return type: " + - returnType.getParameterType().getName() + " in method: " + returnType.getMethod()); + throw new UnsupportedOperationException("Unexpected return type [" + + returnType.getParameterType().getName() + "] in method: " + returnType.getMethod()); } } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java index 52a2756ac1..3915259ae7 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -70,8 +70,8 @@ public class ModelMethodProcessor implements HandlerMethodArgumentResolver, Hand } else { // should not happen - throw new UnsupportedOperationException("Unexpected return type: " + - returnType.getParameterType().getName() + " in method: " + returnType.getMethod()); + throw new UnsupportedOperationException("Unexpected return type [" + + returnType.getParameterType().getName() + "] in method: " + returnType.getMethod()); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PrincipalMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PrincipalMethodArgumentResolver.java index 751e3e743b..dff70178ea 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PrincipalMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PrincipalMethodArgumentResolver.java @@ -38,29 +38,24 @@ import org.springframework.web.method.support.ModelAndViewContainer; */ public class PrincipalMethodArgumentResolver implements HandlerMethodArgumentResolver { - @Override public boolean supportsParameter(MethodParameter parameter) { - Class paramType = parameter.getParameterType(); - return Principal.class.isAssignableFrom(paramType); + return Principal.class.isAssignableFrom(parameter.getParameterType()); } @Override public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { - Class paramType = parameter.getParameterType(); - HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); if (request == null) { - throw new IllegalStateException( - "Current request is not of type [HttpServletRequest]: " + webRequest); + throw new IllegalStateException("Current request is not of type HttpServletRequest: " + webRequest); } Principal principal = request.getUserPrincipal(); - if (principal != null && !paramType.isInstance(principal)) { - throw new IllegalStateException( - "Current user principal is not of type [" + paramType.getName() + "]: " + principal); + if (principal != null && !parameter.getParameterType().isInstance(principal)) { + throw new IllegalStateException("Current user principal is not of type [" + + parameter.getParameterType().getName() + "]: " + principal); } return principal;