From 64a01d64c5a6fa963d93d8430b318fe1dd6eb4f4 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 11 May 2015 14:42:45 +0200 Subject: [PATCH] Polishing --- .../InjectAnnotationAutowireContextTests.java | 14 +++++------ .../springframework/util/ReflectionUtils.java | 9 +++---- .../support/WebRequestDataBinderTests.java | 24 ++++++++++++++++++- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/spring-context/src/test/java/org/springframework/beans/factory/support/InjectAnnotationAutowireContextTests.java b/spring-context/src/test/java/org/springframework/beans/factory/support/InjectAnnotationAutowireContextTests.java index 2c0be0e6bb..fcceb3fb3b 100644 --- a/spring-context/src/test/java/org/springframework/beans/factory/support/InjectAnnotationAutowireContextTests.java +++ b/spring-context/src/test/java/org/springframework/beans/factory/support/InjectAnnotationAutowireContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -667,27 +667,27 @@ public class InjectAnnotationAutowireContextTests { @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Qualifier - public static @interface TestQualifier { + public @interface TestQualifier { } @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) @Qualifier - public static @interface TestQualifierWithDefaultValue { + public @interface TestQualifierWithDefaultValue { - public abstract String value() default "default"; + String value() default "default"; } @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) @Qualifier - public static @interface TestQualifierWithMultipleAttributes { + public @interface TestQualifierWithMultipleAttributes { - public abstract String value() default "default"; + String value() default "default"; - public abstract int number(); + int number(); } } diff --git a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java index f14d952d67..95b491edde 100644 --- a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java @@ -92,7 +92,8 @@ public abstract class ReflectionUtils { while (!Object.class.equals(searchType) && searchType != null) { Field[] fields = getDeclaredFields(searchType); for (Field field : fields) { - if ((name == null || name.equals(field.getName())) && (type == null || type.equals(field.getType()))) { + if ((name == null || name.equals(field.getName())) && + (type == null || type.equals(field.getType()))) { return field; } } @@ -418,8 +419,7 @@ public abstract class ReflectionUtils { i--; } return ((i > CGLIB_RENAMED_METHOD_PREFIX.length()) && - (i < name.length() - 1) && - (name.charAt(i) == '$')); + (i < name.length() - 1) && name.charAt(i) == '$'); } return false; } @@ -433,7 +433,8 @@ public abstract class ReflectionUtils { * @see java.lang.reflect.Field#setAccessible */ public static void makeAccessible(Field field) { - if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers()) || + if ((!Modifier.isPublic(field.getModifiers()) || + !Modifier.isPublic(field.getDeclaringClass().getModifiers()) || Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) { field.setAccessible(true); } diff --git a/spring-web/src/test/java/org/springframework/web/bind/support/WebRequestDataBinderTests.java b/spring-web/src/test/java/org/springframework/web/bind/support/WebRequestDataBinderTests.java index c8b3a0a377..6ec3f5b580 100644 --- a/spring-web/src/test/java/org/springframework/web/bind/support/WebRequestDataBinderTests.java +++ b/spring-web/src/test/java/org/springframework/web/bind/support/WebRequestDataBinderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -147,6 +147,28 @@ public class WebRequestDataBinderTests { assertFalse(target.isPostProcessed()); } + @Test + public void testFieldDefaultWithNestedProperty() throws Exception { + TestBean target = new TestBean(); + target.setSpouse(new TestBean()); + WebRequestDataBinder binder = new WebRequestDataBinder(target); + + MockHttpServletRequest request = new MockHttpServletRequest(); + request.addParameter("!spouse.postProcessed", "on"); + request.addParameter("_spouse.postProcessed", "visible"); + request.addParameter("spouse.postProcessed", "on"); + binder.bind(new ServletWebRequest(request)); + assertTrue(((TestBean) target.getSpouse()).isPostProcessed()); + + request.removeParameter("spouse.postProcessed"); + binder.bind(new ServletWebRequest(request)); + assertTrue(((TestBean) target.getSpouse()).isPostProcessed()); + + request.removeParameter("!spouse.postProcessed"); + binder.bind(new ServletWebRequest(request)); + assertFalse(((TestBean) target.getSpouse()).isPostProcessed()); + } + @Test public void testFieldDefaultNonBoolean() throws Exception { TestBean target = new TestBean();