You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by sv...@apache.org on 2018/06/10 20:34:21 UTC
wicket git commit: WICKET-6560 no warning for null
Repository: wicket
Updated Branches:
refs/heads/master a697cab87 -> 950403d5c
WICKET-6560 no warning for null
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/950403d5
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/950403d5
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/950403d5
Branch: refs/heads/master
Commit: 950403d5ccea5643e6005450c6b808ea72079d59
Parents: a697cab
Author: Sven Meier <sv...@apache.org>
Authored: Sun Jun 10 22:33:58 2018 +0200
Committer: Sven Meier <sv...@apache.org>
Committed: Sun Jun 10 22:33:58 2018 +0200
----------------------------------------------------------------------
.../org/apache/wicket/model/ChainingModel.java | 2 +-
.../apache/wicket/model/ChainingModelTest.java | 103 +++++++++++++++++++
2 files changed, 104 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/950403d5/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java b/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java
index fa0ca7a..4b65b76 100644
--- a/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java
+++ b/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java
@@ -48,7 +48,7 @@ public class ChainingModel<T> implements IChainingModel<T>
+ "in models directly as it may lead to serialization problems. "
+ "If you need to access a property of the session via the model use the "
+ "page instance as the model object and 'session.attribute' as the path.");
- } else if (modelObject instanceof Serializable == false)
+ } else if (modelObject != null && (modelObject instanceof Serializable == false))
{
LOG.warn("It is not a good idea to reference a non-serializable instance "
+ "in models directly as it may lead to serialization problems.");
http://git-wip-us.apache.org/repos/asf/wicket/blob/950403d5/wicket-core/src/test/java/org/apache/wicket/model/ChainingModelTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/model/ChainingModelTest.java b/wicket-core/src/test/java/org/apache/wicket/model/ChainingModelTest.java
new file mode 100644
index 0000000..6b64d44
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/model/ChainingModelTest.java
@@ -0,0 +1,103 @@
+/*
+ * 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.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * Test for {@link ChainingModel}.
+ *
+ * @author svenmeier
+ */
+public class ChainingModelTest
+{
+ @Test
+ public void testNonModel() {
+ ChainingModel<Integer> model = new ChainingModel<>(1);
+
+ assertEquals(Integer.valueOf(1), model.getObject());
+ model.setObject(2);
+ assertEquals(Integer.valueOf(2), model.getObject());
+ }
+
+ @Test
+ public void testDetachable() {
+ class TestDetachable implements IDetachable
+ {
+ boolean detached = false;
+
+ @Override
+ public void detach()
+ {
+ detached = true;
+ }
+ };
+ TestDetachable test = new TestDetachable();
+
+ ChainingModel<TestDetachable> model = new ChainingModel<>(test);
+ assertSame(test, model.getObject());
+
+ test = new TestDetachable();
+ model.setObject(test);
+ assertSame(test, model.getObject());
+
+ model.detach();
+ assertTrue(test.detached);
+ }
+
+ @Test
+ public void testModel() {
+ class TestModel implements IModel<Integer>
+ {
+ boolean detached = false;
+ int value = 1;
+
+ @Override
+ public Integer getObject()
+ {
+ return value;
+ }
+
+ @Override
+ public void setObject(Integer object)
+ {
+ this.value = object;
+ }
+
+ @Override
+ public void detach()
+ {
+ detached = true;
+ }
+ };
+ TestModel test = new TestModel();
+
+ ChainingModel<Integer> model = new ChainingModel<>(test);
+
+ assertEquals(Integer.valueOf(1), model.getObject());
+
+ model.setObject(2);
+ assertEquals(2, test.value);
+
+ model.detach();
+ assertTrue(test.detached);
+ }
+}
\ No newline at end of file
Re: wicket git commit: WICKET-6560 no warning for null
Posted by Martin Grigorov <mg...@apache.org>.
On Sun, Jun 10, 2018 at 11:34 PM, <sv...@apache.org> wrote:
> Repository: wicket
> Updated Branches:
> refs/heads/master a697cab87 -> 950403d5c
>
>
> WICKET-6560 no warning for null
>
>
> Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
> Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/950403d5
> Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/950403d5
> Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/950403d5
>
> Branch: refs/heads/master
> Commit: 950403d5ccea5643e6005450c6b808ea72079d59
> Parents: a697cab
> Author: Sven Meier <sv...@apache.org>
> Authored: Sun Jun 10 22:33:58 2018 +0200
> Committer: Sven Meier <sv...@apache.org>
> Committed: Sun Jun 10 22:33:58 2018 +0200
>
> ----------------------------------------------------------------------
> .../org/apache/wicket/model/ChainingModel.java | 2 +-
> .../apache/wicket/model/ChainingModelTest.java | 103 +++++++++++++++++++
> 2 files changed, 104 insertions(+), 1 deletion(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/wicket/blob/
> 950403d5/wicket-core/src/main/java/org/apache/wicket/model/
> ChainingModel.java
> ----------------------------------------------------------------------
> diff --git a/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java
> b/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java
> index fa0ca7a..4b65b76 100644
> --- a/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java
> +++ b/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java
> @@ -48,7 +48,7 @@ public class ChainingModel<T> implements
> IChainingModel<T>
> + "in models directly as it may
> lead to serialization problems. "
> + "If you need to access a
> property of the session via the model use the "
> + "page instance as the model
> object and 'session.attribute' as the path.");
> - } else if (modelObject instanceof Serializable == false)
> + } else if (modelObject != null && (modelObject instanceof
> Serializable == false))
> {
> LOG.warn("It is not a good idea to reference a
> non-serializable instance "
> + "in models directly as it may
> lead to serialization problems.");
>
Would it be useful to say something about the problematic modelObject in
this warning message, e.g. its class and maybe its value ? For easier
tracking.
>
> http://git-wip-us.apache.org/repos/asf/wicket/blob/
> 950403d5/wicket-core/src/test/java/org/apache/wicket/model/
> ChainingModelTest.java
> ----------------------------------------------------------------------
> diff --git a/wicket-core/src/test/java/org/apache/wicket/model/ChainingModelTest.java
> b/wicket-core/src/test/java/org/apache/wicket/model/ChainingModelTest.java
> new file mode 100644
> index 0000000..6b64d44
> --- /dev/null
> +++ b/wicket-core/src/test/java/org/apache/wicket/model/
> ChainingModelTest.java
> @@ -0,0 +1,103 @@
> +/*
> + * 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.model;
> +
> +import static org.junit.Assert.assertEquals;
> +import static org.junit.Assert.assertSame;
> +import static org.junit.Assert.assertTrue;
> +
> +import org.junit.Test;
> +
> +/**
> + * Test for {@link ChainingModel}.
> + *
> + * @author svenmeier
> + */
> +public class ChainingModelTest
> +{
> + @Test
> + public void testNonModel() {
> + ChainingModel<Integer> model = new ChainingModel<>(1);
> +
> + assertEquals(Integer.valueOf(1), model.getObject());
> + model.setObject(2);
> + assertEquals(Integer.valueOf(2), model.getObject());
> + }
> +
> + @Test
> + public void testDetachable() {
> + class TestDetachable implements IDetachable
> + {
> + boolean detached = false;
> +
> + @Override
> + public void detach()
> + {
> + detached = true;
> + }
> + };
> + TestDetachable test = new TestDetachable();
> +
> + ChainingModel<TestDetachable> model = new
> ChainingModel<>(test);
> + assertSame(test, model.getObject());
> +
> + test = new TestDetachable();
> + model.setObject(test);
> + assertSame(test, model.getObject());
> +
> + model.detach();
> + assertTrue(test.detached);
> + }
> +
> + @Test
> + public void testModel() {
> + class TestModel implements IModel<Integer>
> + {
> + boolean detached = false;
> + int value = 1;
> +
> + @Override
> + public Integer getObject()
> + {
> + return value;
> + }
> +
> + @Override
> + public void setObject(Integer object)
> + {
> + this.value = object;
> + }
> +
> + @Override
> + public void detach()
> + {
> + detached = true;
> + }
> + };
> + TestModel test = new TestModel();
> +
> + ChainingModel<Integer> model = new ChainingModel<>(test);
> +
> + assertEquals(Integer.valueOf(1), model.getObject());
> +
> + model.setObject(2);
> + assertEquals(2, test.value);
> +
> + model.detach();
> + assertTrue(test.detached);
> + }
> +}
> \ No newline at end of file
>
>