You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2019/10/10 10:44:28 UTC

[wicket] branch wicket-8.x updated: WICKET-6707 Property setter parameter type is assumed to be equal to getter return type

This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch wicket-8.x
in repository https://gitbox.apache.org/repos/asf/wicket.git


The following commit(s) were added to refs/heads/wicket-8.x by this push:
     new a3c19f7  WICKET-6707 Property setter parameter type is assumed to be equal to getter return type
a3c19f7 is described below

commit a3c19f7daaf0cf6bf121bf8667987b7b3e672ce2
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Thu Oct 10 13:40:35 2019 +0300

    WICKET-6707 Property setter parameter type is assumed to be equal to getter return type
    
    Use the setter instead of the getter when checking in PropertyResolver#setValue()
    
    (cherry picked from commit 80e9119eb04b8c670c24a97c89c28ddcebc1374b)
---
 .../wicket/core/util/lang/PropertyResolver.java    |  2 +-
 .../org/apache/wicket/util/lang/BooleanBean.java   | 33 ++++++++++++++++++++++
 .../wicket/util/lang/PropertyResolverTest.java     | 16 +++++++++--
 3 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/lang/PropertyResolver.java b/wicket-core/src/main/java/org/apache/wicket/core/util/lang/PropertyResolver.java
index ba5c48b..17dfe27 100644
--- a/wicket-core/src/main/java/org/apache/wicket/core/util/lang/PropertyResolver.java
+++ b/wicket-core/src/main/java/org/apache/wicket/core/util/lang/PropertyResolver.java
@@ -983,7 +983,7 @@ public final class PropertyResolver
 							"]. Can't convert value: " + value + " to class: " +
 							getMethod.getReturnType() + " for setting it on " + object);
 					}
-					else if (getMethod.getReturnType().isPrimitive())
+					else if (setMethod != null && setMethod.getParameterTypes()[0].isPrimitive())
 					{
 						throw new ConversionException("Method [" + getMethod +
 							"]. Can't convert null value to a primitive class: " +
diff --git a/wicket-core/src/test/java/org/apache/wicket/util/lang/BooleanBean.java b/wicket-core/src/test/java/org/apache/wicket/util/lang/BooleanBean.java
new file mode 100644
index 0000000..63e8a93
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/util/lang/BooleanBean.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.util.lang;
+
+/**
+ * Bean for {@link PropertyResolverTest#booleanVsBoolean()}
+ */
+public class BooleanBean
+{
+	private Boolean instantPayment;
+
+	public boolean isInstantPayment() {
+		return instantPayment != null && instantPayment;
+	}
+
+	public void setInstantPayment(final Boolean instantPayment) {
+		this.instantPayment = instantPayment;
+	}
+}
diff --git a/wicket-core/src/test/java/org/apache/wicket/util/lang/PropertyResolverTest.java b/wicket-core/src/test/java/org/apache/wicket/util/lang/PropertyResolverTest.java
index f3243be..8ba00f0 100644
--- a/wicket-core/src/test/java/org/apache/wicket/util/lang/PropertyResolverTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/util/lang/PropertyResolverTest.java
@@ -766,7 +766,19 @@ public class PropertyResolverTest extends WicketTestCase
 		assertEquals("string", PropertyResolver.getValue("string", document));
 		assertEquals("string2", PropertyResolver.getValue("nested.string", document));
 	}
-	
+
+	/**
+	 * https://issues.apache.org/jira/browse/WICKET-6707
+	 */
+	@Test
+	public void booleanVsBoolean()
+	{
+		final BooleanBean bean = new BooleanBean();
+		PropertyResolver.setValue("instantPayment", bean, null, CONVERTER);
+		Boolean instantPayment = (Boolean) PropertyResolver.getValue("instantPayment", bean);
+		assertFalse(instantPayment);
+	}
+
 	class CustomGetAndSetLocator implements IPropertyLocator {
 
 		private IPropertyLocator locator = new DefaultPropertyLocator();
@@ -806,4 +818,4 @@ public class PropertyResolverTest extends WicketTestCase
 			}
 		}
 	}
-}
\ No newline at end of file
+}