Repository: wicket
Updated Branches:
  refs/heads/wicket-6.x ea376d906 -> 68f8390cf


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/68f8390c
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/68f8390c
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/68f8390c

Branch: refs/heads/wicket-6.x
Commit: 68f8390cf18dcaa8a847300698df7913f69fbcb6
Parents: ea376d9
Author: Martin Tzvetanov Grigorov <mgrigo...@apache.org>
Authored: Mon Nov 2 21:17:01 2015 +0100
Committer: Martin Tzvetanov Grigorov <mgrigo...@apache.org>
Committed: Mon Nov 2 21:18:31 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/68f8390c/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 91085c2..97e9045 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/68f8390c/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);
+       }
+}

Reply via email to