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 2015/11/02 21:18:23 UTC

wicket git commit: WICKET-6020 GuiceFieldValueFactory returns the NULL_SENTINEL from the cache

Repository: wicket
Updated Branches:
  refs/heads/wicket-7.x 052c40321 -> 21d80950b


WICKET-6020 GuiceFieldValueFactory returns the NULL_SENTINEL from the cache


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/21d80950
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/21d80950
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/21d80950

Branch: refs/heads/wicket-7.x
Commit: 21d80950b9eb6aa7265ace8b27056e8d112f2330
Parents: 052c403
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Mon Nov 2 21:17:01 2015 +0100
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Mon Nov 2 21:18:10 2015 +0100

----------------------------------------------------------------------
 .../wicket/guice/GuiceFieldValueFactory.java    |  2 +-
 .../guice/GuiceFieldValueFactoryTest.java       | 58 ++++++++++++++++++++
 2 files changed, 59 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/21d80950/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceFieldValueFactory.java
----------------------------------------------------------------------
diff --git a/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceFieldValueFactory.java b/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceFieldValueFactory.java
index 2726b2a..c770554 100644
--- a/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceFieldValueFactory.java
+++ b/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceFieldValueFactory.java
@@ -73,7 +73,7 @@ public class GuiceFieldValueFactory implements IFieldValueFactory
 					Object cachedValue = cache.get(locator);
 					if (cachedValue != null)
 					{
-						return cachedValue;
+						return cachedValue == NULL_SENTINEL ? null : cachedValue;
 					}
 
 					target = locator.locateProxyTarget();

http://git-wip-us.apache.org/repos/asf/wicket/blob/21d80950/wicket-guice/src/test/java/org/apache/wicket/guice/GuiceFieldValueFactoryTest.java
----------------------------------------------------------------------
diff --git a/wicket-guice/src/test/java/org/apache/wicket/guice/GuiceFieldValueFactoryTest.java b/wicket-guice/src/test/java/org/apache/wicket/guice/GuiceFieldValueFactoryTest.java
new file mode 100644
index 0000000..ba0a76c
--- /dev/null
+++ b/wicket-guice/src/test/java/org/apache/wicket/guice/GuiceFieldValueFactoryTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.guice;
+
+import java.lang.reflect.Field;
+
+import org.junit.Test;
+
+/**
+ * Tests for GuiceFieldValueFactory
+ */
+public class GuiceFieldValueFactoryTest extends AbstractInjectorTest
+{
+	/**
+	 * https://issues.apache.org/jira/browse/WICKET-6020
+	 */
+	@Test
+	public void getFieldValueShouldReturnNullEvenWhenUsingTheCache() throws Exception
+	{
+		GuiceFieldValueFactory factory = new GuiceFieldValueFactory(false);
+		TestComponent owner = new TestComponent("id");
+		Field field = TestComponent.class.getDeclaredField("injectedOptionalField");
+
+		// no cache
+		Object value = factory.getFieldValue(field, owner);
+		assertNull(value);
+
+		// from cache
+		Object value2 = factory.getFieldValue(field, owner);
+		assertNull(value2);
+	}
+
+	@Override
+	protected TestNoComponentInterface newTestNoComponent()
+	{
+		return new TestNoComponent();
+	}
+
+	@Override
+	protected TestComponentInterface newTestComponent(String id)
+	{
+		return new TestComponent(id);
+	}
+}