From: Artur Signell Date: Mon, 1 Oct 2012 11:08:33 +0000 (+0300) Subject: Avoid throwing exceptions from toString, log message instead (#9804) X-Git-Tag: 7.0.0.beta3~4^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fchanges%2F26%2F26%2F1;p=vaadin-framework.git Avoid throwing exceptions from toString, log message instead (#9804) Change-Id: Ia2f8504a0fe75ab3a7c4746d533e5fd012e2a69c --- diff --git a/server/src/com/vaadin/data/util/AbstractProperty.java b/server/src/com/vaadin/data/util/AbstractProperty.java index 76d47039d0..aefe00ad32 100644 --- a/server/src/com/vaadin/data/util/AbstractProperty.java +++ b/server/src/com/vaadin/data/util/AbstractProperty.java @@ -18,6 +18,7 @@ package com.vaadin.data.util; import java.util.Collection; import java.util.Collections; import java.util.LinkedList; +import java.util.logging.Logger; import com.vaadin.data.Property; @@ -78,9 +79,17 @@ public abstract class AbstractProperty implements Property, @Deprecated @Override public String toString() { - throw new UnsupportedOperationException( - "Use Property.getValue() instead of " + getClass() - + ".toString()"); + getLogger() + .warning( + "You are using Property.toString() instead of getValue() to get the value for a " + + getClass().getSimpleName() + + ". This will not be supported starting from Vaadin 7.1 " + + "(your debugger might call toString() and cause this message to appear)."); + T v = getValue(); + if (v == null) { + return null; + } + return v.toString(); } /* Events */ @@ -277,4 +286,7 @@ public abstract class AbstractProperty implements Property, return Collections.EMPTY_LIST; } + private static Logger getLogger() { + return Logger.getLogger(AbstractProperty.class.getName()); + } } diff --git a/server/src/com/vaadin/data/util/IndexedContainer.java b/server/src/com/vaadin/data/util/IndexedContainer.java index e957d958a9..7273b28b66 100644 --- a/server/src/com/vaadin/data/util/IndexedContainer.java +++ b/server/src/com/vaadin/data/util/IndexedContainer.java @@ -28,6 +28,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.logging.Logger; import com.vaadin.data.Container; import com.vaadin.data.Item; @@ -961,8 +962,21 @@ public class IndexedContainer extends @Deprecated @Override public String toString() { - throw new UnsupportedOperationException( - "Use Property.getValue() instead of IndexedContainerProperty.toString()"); + getLogger() + .warning( + "You are using IndexedContainerProperty.toString() instead of getValue() to get the value for a " + + getClass().getSimpleName() + + ". This will not be supported starting from Vaadin 7.1 " + + "(your debugger might call toString() and cause this message to appear)."); + Object v = getValue(); + if (v == null) { + return null; + } + return v.toString(); + } + + private Logger getLogger() { + return Logger.getLogger(IndexedContainerProperty.class.getName()); } /** diff --git a/server/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java b/server/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java index 6e5ba0dc57..bd6b1a75bf 100644 --- a/server/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java +++ b/server/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java @@ -18,6 +18,7 @@ package com.vaadin.data.util.sqlcontainer; import java.sql.Date; import java.sql.Time; import java.sql.Timestamp; +import java.util.logging.Logger; import com.vaadin.data.Property; import com.vaadin.data.util.converter.Converter.ConversionException; @@ -261,8 +262,21 @@ final public class ColumnProperty implements Property { @Deprecated @Override public String toString() { - throw new UnsupportedOperationException( - "Use ColumnProperty.getValue() instead of ColumnProperty.toString()"); + getLogger() + .warning( + "You are using ColumnProperty.toString() instead of getValue() to get the value for a " + + getClass().getSimpleName() + + ". This will not be supported starting from Vaadin 7.1 " + + "(your debugger might call toString() and cause this message to appear)."); + Object v = getValue(); + if (v == null) { + return null; + } + return v.toString(); + } + + private static Logger getLogger() { + return Logger.getLogger(ColumnProperty.class.getName()); } public void setOwner(RowItem owner) {